This repos allows you to generate python Layers for lambda in AWS.
Lambda is an amazing AWS Service allowing you to develop serverless functions.
There is a full detailed tutorial on medium on how to use this repo: [Link to Medium Tutorial](link to it)
You must have Docker Installed. You can get Docker following this link: Get Docker
- Clone this repository
- Build the Docker Image which will be used you to build the layer
By default the python version installed in the docker image is 3.7.12, but you can change it using the Docker Arg python_version
In the following example, the python 3.7.12 is used.
(Available python versions can be seen at Python Versions)
git clone https://github.com/LeoCyclope/aws-python-lambda-layers-generator-docker.git
cd aws-python-lambda-layers-generator-docker
docker build --build-arg python_version=3.7.12 . -t aws-lambda-layer-generator
- Update the requirements.txt with the libraries you want your layer to contain.
- By the default the current requirements.txt will install Opencv and Pillow.
- Change the python version according to the runtime used in lambda:
- You can change the python_version docker ARG when building you Dockerfile to match the runtime.
- When Executing, change the python lib folder path to match the runtime you chose in Lambda AWS.
- Ex: python/lib/python3.7/site-packages/ should be changed to python/lib/python3.8/site-packages/ if you chose the runtime 3.8
docker run --rm -v ${PWD}:/workdir aws-lambda-layer-generator /bin/bash -c "mkdir layer && cd layer && pip install -r /workdir/requirements.txt -t python/lib/python3.7/site-packages/ && zip -r layer.zip * && cp layer.zip /workdir"
(Change the export path to match the runtime version you chose : python/lib/python3.7/site-packages/)
docker run --rm -v $PWD:/workdir aws-lambda-layer-generator /bin/bash -c "mkdir layer && cd layer && pip install -r /workdir/requirements.txt -t python/lib/python3.7/site-packages/ && zip -r layer.zip * && cp layer.zip /workdir"
(Change the export path to match the runtime version you chose : python/lib/python3.7/site-packages/)
The output of the command lines above will me a .zip called "layer.zip" which will is the file required to build your layer.
There is a full detailed tutorial on medium on how to use this repo: Link to Medium Tutorial
Thanks to this repo which helped me generalize my docker file: (https://github.com/awslabs/lambda-opencv)