Created
July 30, 2020 15:17
-
-
Save stekern/393a3a9e5cbfe6de77aeabe9942ffbdc to your computer and use it in GitHub Desktop.
Verify a shell command in an AWS Lambda function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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