Skip to content

Python lambda layer creation and deployment

Create directory to store packages

mkdir python

Download packages

To create a layer for a specific python version (like python3.7) or if same package can be used in multiple python version

pip install <package-name> -t python

To have packages unique to multiple regions

pip install <package-name> -t python/lib/python<python-version>/site-packages
pip install psycopg2-binary -t python/lib/python3.9/site-packages
pip install psycopg2-binary -t python/lib/python3.7/site-packages

Create zip for layer

zip -r <layer-name> python
zip -r some_layer python

Upload layer

aws --region <region-name> lambda publish-layer-version --layer-name <layer-name> --description <description> --compatible-runtimes "<python-version-x>" "<python-version-y>" --zip-file fileb://<layer-zip-file-path>
aws --region us-east-1 lambda publish-layer-version --layer-name some_layer --description "My random packages" --compatible-runtimes "python3.7" "python3.9" --zip-file fileb://some_layer.zip
Back to top