简体   繁体   中英

how to invoke bash script with aws lambda function in python?

I want to invoke a bash script with name myScript.sh in a newly created lambda function.

Step 1: I created a lambda function with name myLambda.py and the source code like:

import subprocess
print("start") 
subprocess.call("./myScript.sh")"

Step 2: Create a bash script with name myScript.sh under the same path with myLambda.py

Step 3: Click the test button and got the response:

{
  "errorMessage": "[Errno 13] Permission denied: './myScript.sh'"
}

Anybody knows how to deal with the permission denied issue in aws lambda function env?

Since the files are added as the guideline in https://docs.aws.amazon.com/lambda/latest/dg/code-editor.html , it's not helpful to use linux command "chmod +x " to change the file permission.

It's resolved by move myScript.sh to /tmp folder and add permission change command:

subprocess.run(["chmod", "+x", "/tmp/myScript.sh"])

You can't execute scripts that don't have execute permission. You can supply execute permissions using some variant of:

chmod +x /somepath/myScript.sh

You can run this using your current subprocess approach. Run chmod before you run myScript.sh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM