Under the folder Compatible Packages, you can just download these packages that are already compatible to AWS Lambda runtime.
A repository explaining how to make Python Libraries into AWS Lambda compatible packages as a Layer.
If you are using LinuxOS, this YouTube tutorial would satify your needs.
AWS lambda with OpenCV via Layers, video by Srce Cde - https://youtu.be/FQBT8vVRkAg
In short,
- Using Linux Terminal, pip3 install the Python libraries you want into a specific folder of directory build/python/lib/python3.8/site-packages
For more information on the directory to use, take a look at: AWS Developer Guide - Including library dependencies in a layer - https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path - then zip up the python folder at build/python. In your /build directory, you should have the /python/lib/python3.8/site-packages folder and the zipped folder (python.zip)
- Create a S3 bucket (this bucket needs to be in the same region as your AWS Lambda function)
- Upload the zip file.
- Go to AWS Lambda, create a new layer, upload file from S3.
- Use this layer in your AWS Lambda function.
- Now, you can import that library in your function's code!
If you are using WindowsOS, following the steps for LinuxOS will not work. This is because, AWS Lambda runs in the amazonlinux OS. And the package you created by following the LinuxOS is configurated/build for your local WindowsOS environment.
There are multiple ways to go about this:
- Docker and EC2
Compiling the libraries in an instance type of amazonlinux OS environment
- Medium - How to create an AWS Lambda python 3.6 deployment package using Docker - https://medium.com/i-like-big-data-and-i-cannot-lie/how-to-create-an-aws-lambda-python-3-6-deployment-package-using-docker-d0e847207dd6
- GitHub Link - lambda layers for python runtime by hidekuma - https://github.com/hidekuma/lambda-layers-for-python-runtime
- Using pypi and wheel
This is by far the easiest.
AWS Support - How do I add Python packages with compiled binaries to my deployment package and make the package compatible with Lambda? - https://aws.amazon.com/premiumsupport/knowledge-center/lambda-python-package-compatible/
Rephrasing:- At pypi.org. https://pypi.org/ , search the library that you want and navigate to the Download Files page
eg, https://pypi.org/project/numpy/#files - Download appropriate .whl file
eg,
For Python 3.8, download numpy-1.19.1-cp38-cp38-manylinux1_x86_64.whl
For Python 3.7, download numpy-1.19.1-cp37-cp37m-manylinux1_x86_64.whl - Check if you have wheel library in your environment.
- Using command prompt, check if you have wheel installed
pip3 show wheel
- To install wheel, type
pip3 install wheel
- Uncompress wheel file
wheel unpack <dir-to-wheel_file>
-
Move the relevant folders into a directory build\python\lib\python3.8\site-packages
eg, in the case for (opencv) cv2, dlib, imutils, numpy, your build\python\lib\python3.8\site-packages should look like this
-
Zip up the python folder at build\python.
In your \build directory, you should have the build\python\lib\python3.8\site-packages folder and the zipped folder (python.zip) -
Create a S3 bucket (this bucket needs to be in the same region as your AWS Lambda function)
-
Upload the zip file.
-
Go to AWS Lambda, create a new layer, upload file from S3.
-
Use this layer in your AWS Lambda function.
-
Now, you can import that library in your function's code!
- At pypi.org. https://pypi.org/ , search the library that you want and navigate to the Download Files page