Not able to run aws cli commands in lambda function
Closed this issue · 2 comments
ravikande8636 commented
Not able to run aws cli commands after adding this lambda layer, Here is my code
import subprocess
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def run_command(command):
command_list = command.split(' ')
#print(command_list)
try:
logger.info("Running shell command: \"{}\"".format(command))
result = subprocess.run(command_list, stderr=subprocess.STDOUT, stdout=subprocess.PIPE);
#print(result)
logger.info("Command output:\n---\n{}\n---".format(result.stdout.decode('UTF-8')))
except Exception as e:
logger.error("Exception: {}".format(e))
return False
return result
def lambda_handler(event, context):
run_command('/opt/awscli/aws --version')
run_command('/opt/awscli/aws s3 ls')
It is failing with these errors
Function Logs
START RequestId: 10dd8da3-3325-4195-a522-ed79d0120430 Version: $LATEST
[INFO] 2021-10-15T22:25:29.943Z 10dd8da3-3325-4195-a522-ed79d0120430 Running shell command: "/opt/awscli/aws --version"
[INFO] 2021-10-15T22:25:29.967Z 10dd8da3-3325-4195-a522-ed79d0120430 Command output:
---
/opt/awscli/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
---
[INFO] 2021-10-15T22:25:29.985Z 10dd8da3-3325-4195-a522-ed79d0120430 Running shell command: "/opt/awscli/aws s3 ls"
[INFO] 2021-10-15T22:25:30.5Z 10dd8da3-3325-4195-a522-ed79d0120430 Command output:
---
/opt/awscli/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
---
END RequestId: 10dd8da3-3325-4195-a522-ed79d0120430
REPORT RequestId: 10dd8da3-3325-4195-a522-ed79d0120430 Duration: 83.23 ms Billed Duration: 84 ms Memory Size: 128 MB Max Memory Used: 38 MB Init Duration: 126.17 ms
Request ID
10dd8da3-3325-4195-a522-ed79d0120430
github-actions commented
This issue is now marked as stale because it hasn't seen activity for a while. Add a comment or it will be closed soon.
github-actions commented
Closing this issue as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen.