Skip to content

Instantly share code, notes, and snippets.

@rustyeddy
Last active September 22, 2017 00:55
Show Gist options
  • Save rustyeddy/40248a5f5d3586b11064cceca726e7c1 to your computer and use it in GitHub Desktop.
Save rustyeddy/40248a5f5d3586b11064cceca726e7c1 to your computer and use it in GitHub Desktop.
AWS Lambda - running a bashscript from python
import logging
import subprocess
def lambda_handler(event, context):
# Probably get the script name from an environment variable or event...
script = "bashscript.sh"
log = logging.getLogger("lambda-logger")
log.setLevel(logging.INFO)
log.info("Attempting to run bash script: " + script)
output = subprocess.check_output(script, stderr=subprocess.STDOUT, shell=True)
outstr = output.decode("utf-8")
log.info(outstr)
return outstr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment