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.
pip install requests -t .
The above command will install the python packages and its dependencies in the current folder, which is
The contents of the folder look like this to me
nameenter the desired name. Click on
upload a zip fileand 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.