Skip to content

Instantly share code, notes, and snippets.

@stekern
Created July 30, 2020 15:17
Show Gist options
  • Save stekern/393a3a9e5cbfe6de77aeabe9942ffbdc to your computer and use it in GitHub Desktop.
Save stekern/393a3a9e5cbfe6de77aeabe9942ffbdc to your computer and use it in GitHub Desktop.
Verify a shell command in an AWS Lambda function
import subprocess
def lambda_handler(event, context):
shell_command = event.get("shell_command", "")
with open("/tmp/script.sh", "w") as f:
f.write(shell_command)
try:
subprocess.check_call("sh -n /tmp/script.sh", shell=True)
except subprocess.CalledProcessError:
raise ValueError("'shell_command' does not contain a valid shell command")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment