Ask Your Question
0

Why is the AWS Python Lambda function showing an error message saying "requests" module is not found?

asked 2021-07-10 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-09-21 13:00:00 +0000

bukephalos gravatar image

The error message is indicating that the "requests" module, which is a third-party Python library used for making HTTP requests, is not installed in the AWS Lambda environment.

To resolve this issue, you can add the "requests" package to the deployment package that you upload to AWS Lambda. You can do this by either including the package in the same folder as your Lambda function code and zipping the entire folder, or by using a package manager like pip to create a package specifically for your Lambda function.

Here are the steps to add "requests" package:

  1. Create a virtual environment for your Lambda function:
python3 -m venv my-lambda-env
  1. Activate the virtual environment:
source my-lambda-env/bin/activate
  1. Install the "requests" package:
pip install requests
  1. Copy the lambda function file along with the installed packages to a new folder:
mkdir lambda-deploy
cp lambda_file.py lambda-deploy/
pip install -r requirements.txt -t lambda-deploy/
  1. Zip the contents of the lambda-deploy folder:
cd lambda-deploy
zip -r ../lambda-deploy.zip *
  1. Finally, upload the zipped file to AWS Lambda and test the function.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-10 11:00:00 +0000

Seen: 8 times

Last updated: Sep 21 '21