Skip to content

508-dev/python-lambda-layers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda Layers for Python Runtimes

Problem

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

Solution

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

 

Usage

  1. Update requirements.txt with the packages you want in the layer
    Syntax options for requirements.txt
  2. Make sure podman or docker daemon is running
  3. Execute runner.sh script and it will generate the python_layer.zip artifact
  4. Upload python_layer.zip to Lambda Layers and use it in your Python Lambda function(s)

Note

Stating package versions explicitly lowers dependencies, layer size and attack surface

Following is done automatically by runner.sh

  1. Create an Amazon Linux container
  2. Install the required packages written in requirements.txt with pip
  3. Generate the zip file INSIDE the container so as to match the Lambda environment
  4. Output the zip file to your local machine which you can upload to Lambda Layers
  5. Delete the Amazon Linux container and image to free up space (can be disabled in runner.sh file)

 

Supported Defaults

Note

Python Runtime: Python 3.14
Lambda Operating System: Amazon Linux 2023
Architecture: x86_64
Container Runtimes: Podman, Docker

Support for other Python versions

If you wish to build layers for Python runtimes/versions other than 3.14,

  1. 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 the Dockerfile

  2. Update the PYTHON_VERSION argument in the Dockerfile

  3. Execute runner.sh

Future Considerations

  • Support for arm64 architecture
  • Support runtimes for other languages
  • Support other popular container runtimes

About

Quickly create AWS Lambda Layers for Python functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors