Reputation: 67
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"])
Upvotes: 1
Views: 5806
Reputation: 78842
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.
Upvotes: 1