1

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"])

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. I add the myScript.sh with the guideline in docs.aws.amazon.com/lambda/latest/dg/code-editor.html. I don't know how to change the file permission over there since it's not saved in the local machine.
Thank you very much for your prompt reply. Got read-only file system error after using "subprocess.run(["chmod", "+x", "/var/task/myScript.sh"])". It looks the file should under /tmp folder. Fix it by moving the file under /tmp folder.
Can you show your complete myLambda.py, this isnt working for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.