Not all libraries are present in the environment provided by AWS lambda (Obviously! It’s not possible). AWS provides a way to tackle this problem. If you want to use a common library (present in pip or a custom library) across various lambda functions, layers are the way to do it.
As of today, lambda does not provide requests
. It is a commonly used library in python. I will take this as an example and create a layer for it in AWS.
python
pip install requests -t .
The above command will install the python packages and its dependencies in the current folder, which is python
.
The contents of the folder look like this to me
Create Layer
.name
enter the desired name. Click on upload a zip file
and upload the file you had zipped earlier. Select the appropriate runtimes and you are done.Congrats!!! Your AWS layer is ready to be used with lambda functions.