Build AWS Lambda deployment packages and layers for multiple Python versions (3.10+) and architectures (x86_64/arm64).
Inspired by LambdaZipper
- 🐍 Multiple Python versions: Support for Python 3.10, 3.11, 3.12, 3.13, and 3.14 (default)
- 🏗️ Multi-architecture: Build for both x86_64 (amd64) and arm64 (aarch64) by default
- 📦 Bulk packaging: Uses
requirements.txtby default to package multiple dependencies - 🔄 Two output formats: Single combined archive (default) or individual archives per package
- ⚡ Fast builds: Based on Amazon Linux 2023 for compatibility with Lambda runtime
- 🚀 Zero-config: Run without arguments for sensible defaults
Simply run the build script with no arguments:
./build-multiarch.shDefault behavior:
- Uses Python 3.14 (latest)
- Reads from
requirements.txtin the current directory - Builds for both x86_64 and arm64 architectures
- Creates single combined archive per architecture
Result: combined-python3.14-x86_64.zip and combined-python3.14-aarch64.zip in ./output/
# Use a specific Python version
./build-multiarch.sh --python 3.13
# Build only for x86_64
./build-multiarch.sh --skip-arm64
# Create individual archives per package
./build-multiarch.sh --individual
# Build a single package instead of requirements.txt
./build-multiarch.sh --package numpy
# Combine options
./build-multiarch.sh --python 3.12 --skip-arm64 --individual| Option | Description | Default |
|---|---|---|
--python VERSION |
Python version (3.10-3.14) | 3.14 |
-r, --requirements FILE |
Path to requirements.txt | requirements.txt |
--package NAME |
Single package name (overrides requirements.txt) | - |
--skip-x86, --skip-amd64 |
Skip x86_64 architecture build | Build both |
--skip-arm64 |
Skip arm64 architecture build | Build both |
--individual |
Create individual archives per package | Single combined |
--image NAME |
Custom Docker image name | lambda-zipper |
--help |
Show help message | - |
# Default: Python 3.14, requirements.txt, multi-arch, combined archive
./build-multiarch.sh
# Use different Python version
./build-multiarch.sh --python 3.13
# Build only for x86_64 architecture
./build-multiarch.sh --skip-arm64
# Create individual archives for each package
./build-multiarch.sh --individual
# Use custom requirements file
./build-multiarch.sh -r ./my-requirements.txt
# Build a single package (ignores requirements.txt)
./build-multiarch.sh --package numpy
# Combine multiple options
./build-multiarch.sh --python 3.12 --skip-arm64 --individual -r prod-requirements.txtFor direct Docker control, you can build and run containers manually:
Build a Docker image:
docker build --build-arg PYTHON_VERSION=3.14 -t lambda-zipper .Package a single library:
docker run --rm -v $(pwd)/output:/package lambda-zipper numpydocker run --rm \
-v $(pwd)/requirements.txt:/input/requirements.txt \
-v $(pwd)/output:/package \
lambda-zipperdocker run --rm \
-e SINGLE_FILE=true \
-v $(pwd)/requirements.txt:/input/requirements.txt \
-v $(pwd)/output:/package \
lambda-zipper| Python Version | Amazon Linux 2023 | Installation Method | Status |
|---|---|---|---|
| 3.10 | ✅ Available | dnf package | Supported |
| 3.11 | ✅ Available | dnf package | Supported |
| 3.12 | ✅ Available | dnf package | Supported |
| 3.13 | ✅ Available | dnf package | Supported |
| 3.14 | ⚙️ Built from source | Compiled with optimizations | Supported (Default) |
Note: Python 3.14 is automatically compiled from source when building the Docker image, which takes longer but ensures compatibility with the latest Python version.
python/
lib/
pythonX.Y/
site-packages/
[your packages here]
Upload as a Lambda Layer in the AWS Console.
[your packages at root level]
Extract into your Lambda deployment package alongside your code.
- x86_64 (amd64): Standard Lambda runtime
- arm64 (aarch64): AWS Graviton2 Lambda runtime (cost-effective)
Choose the architecture that matches your Lambda function configuration.
Create requirements.txt:
numpy==1.26.4
pandas==2.1.4
scipy==1.11.4
scikit-learn==1.3.2Build with defaults (Python 3.14, multi-arch, combined archive):
./build-multiarch.shResult: combined-python3.14-x86_64.zip and combined-python3.14-aarch64.zip ready for Lambda Layer
Create requirements.txt:
requests==2.31.0
beautifulsoup4==4.12.2
lxml==4.9.3Build for Python 3.13, x86_64 only:
./build-multiarch.sh --python 3.13 --skip-arm64Create requirements.txt:
Pillow==10.2.0
opencv-python-headless==4.9.0.80
numpy==1.26.4Build individual archives for selective deployment:
./build-multiarch.sh --individualResult: Separate archives for each package, allowing you to pick and choose
Build only boto3 for both architectures:
./build-multiarch.sh --package boto3Result: boto3-python3.14-x86_64.zip and boto3-python3.14-aarch64.zip
Build for Python 3.10 with specific requirements:
./build-multiarch.sh --python 3.10 -r legacy-requirements.txt.
├── Dockerfile # Multi-version, multi-arch capable Docker image
├── package.sh # Packaging script with requirements.txt support
├── build-multiarch.sh # Helper script for multi-arch builds
├── requirements.example.txt
└── readme.md
- Base Image: Uses Amazon Linux 2023 for Lambda runtime compatibility
- Python Installation: Installs specified Python version (3.10-3.14) with development headers
- Package Installation: Uses pip with
--targetflag to install packages - Packaging: Creates zip archives with proper Lambda Layer structure
- Multi-arch: Leverages Docker buildx for platform-specific builds
Enable buildx in Docker Desktop settings or install manually:
docker buildx versionBy default, the script looks for requirements.txt in the current directory. Specify a different file:
./build-multiarch.sh -r path/to/my-requirements.txtThe build includes gcc, g++, and cmake for compiling binary extensions. Most packages should work, but some may require additional system libraries. Modify the Dockerfile to add specific dependencies.
Lambda has a 250MB (unzipped) limit for layers. For large packages:
- Use
--individualflag to split packages into separate archives - Deploy multiple smaller layers
- Use Lambda deployment package directly
- Consider AWS Lambda Extensions or Container Images
Python 3.14 is compiled from source and takes longer. For faster builds:
- Use Python 3.13 or earlier:
./build-multiarch.sh --python 3.13 - Build only one architecture:
./build-multiarch.sh --skip-arm64 - Docker caches layers, so subsequent builds are faster
Add system dependencies:
# Add after the base install in Dockerfile
RUN dnf -y install postgresql-devel libxml2-devel# Build for specific platform
docker buildx build \
--platform linux/amd64 \
--build-arg PYTHON_VERSION=3.14 \
-t lambda-zipper:custom \
--load .
# Run with requirements (combined archive)
docker run --rm \
-e SINGLE_FILE=true \
-v $(pwd)/requirements.txt:/input/requirements.txt \
-v $(pwd)/output:/package \
lambda-zipper:custom
# Run with single package
docker run --rm \
-v $(pwd)/output:/package \
lambda-zipper:custom numpyArchives are named with the following pattern:
Combined archives (default):
combined-python{VERSION}-{ARCH}.zip- Example:
combined-python3.14-x86_64.zip,combined-python3.14-aarch64.zip
Individual package archives (with --individual):
{PACKAGE}-python{VERSION}-{ARCH}.zip- Example:
numpy-python3.14-x86_64.zip,requests-python3.13-aarch64.zip
Feel free to submit issues and enhancement requests!
This project is open source and available for use and modification.