To import packages in AWS Lambda Functions, they are required as Lambda Layers
These layers need to match the language runtime/version, architecture, lambda operating system, etc. Creating these in local environments can cause unforeseen inconsistencies and potential compatibility issues
This repo tries to solve the problem by standardising the environment using a container. The packages are baked into layers inside this standard container. A .zip artifact is generated, which can be easily uploaded to Lambda Layers
- Update
requirements.txtwith the packages you want in the layer
Syntax options for requirements.txt - Make sure podman or docker daemon is running
- Execute
runner.shscript and it will generate thepython_layer.zipartifact - Upload
python_layer.zipto Lambda Layers and use it in your Python Lambda function(s)
Note
Stating package versions explicitly lowers dependencies, layer size and attack surface
- Create an Amazon Linux container
- Install the required packages written in requirements.txt with pip
- Generate the zip file INSIDE the container so as to match the Lambda environment
- Output the zip file to your local machine which you can upload to Lambda Layers
- Delete the Amazon Linux container and image to free up space (can be disabled in
runner.shfile)
Note
Python Runtime: Python 3.14
Lambda Operating System: Amazon Linux 2023
Architecture: x86_64
Container Runtimes: Podman, Docker
If you wish to build layers for Python runtimes/versions other than 3.14,
-
Note the operating system necessary for your python runtime.
This repo uses Amazon Linux 2023 by default. But if your runtime/version needs a different operating system, you can find the specific image tags on amazonlinux dockerhub. Use that tag in theDockerfile -
Update the
PYTHON_VERSIONargument in theDockerfile -
Execute
runner.sh
- Support for arm64 architecture
- Support runtimes for other languages
- Support other popular container runtimes