1

I am trying to add the requests package using the command pipenv install requests. I see that it creates a Pipfile and Piplock. But when I try to execute the lambda function written in python, It gives me an error saying no module called requests found.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Vivek Gr
  • 11
  • 1
  • 2
  • 1
    Might be useful: [Upcoming changes to the Python SDK in AWS Lambda | AWS Compute Blog](https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/) – John Rotenstein Jun 24 '21 at 06:42
  • Please edit your Question to include details of how you included the Requests package in your Lambda function. (For example, whether you created a zip file and uploaded it to the function, etc.) – John Rotenstein Jun 24 '21 at 06:43

1 Answers1

0

You can use Serverless, which is my preference.

Or include the libraries that are not part of Python's standard library, such as requests, you can use lambda's layers.

  1. Create the zip: This is a zip that contains all the libraries you want the Lambda function to use. First, create a folder called python.
$ mkdir python
$ cd python

then, install the Python libraries you need in there. You can do this either with a single library:

pip install --target . requests

or with a list of libraries, i.e. requirements.txt

pip install --target . -r requirements.txt

Finally, zip everything up

zip -r dependencies.zip ../python
  1. Create a layer: You can do this in the AWS console or in the CLI. Follow these instructions.
  2. Add the layer to the lambda function: This can be done with the Add a layer option in the lambda page, or follow these instructions if you want to use the CLI.
Luv_Python
  • 194
  • 6
  • 1
    Instead of copying my answer from [here](https://stackoverflow.com/a/64462403/3390419) step by step, you could have linked to it? – Paolo Jan 12 '22 at 16:31