A tool to package Python AWS Lambda functions with zips, Docker containers, and layers.
Project description
Lambda Packer (BuildKit-Native)
lambda-packer is a "compiler" for AWS Lambda and Layers. Instead of running pip install on your host machine, it compiles your package_config.yaml into a BuildKit execution graph, ensuring your artifacts are always built in a runtime-correct, isolated environment.
🚀 Key Features
- BuildKit-First: Zero host-side dependencies (except Docker). No more "it works on my machine" C-extension issues.
- Standardized Context: Build from any folder on your machine; the tool automatically stages your source and layers.
- Parallel Builds: High-performance execution using
ThreadPoolExecutorand BuildKit's internal graph concurrency. - Multi-Platform: Built-in support for
linux/amd64andlinux/arm64. - Deterministic ZIPs: Reproducible artifacts with fixed timestamps and sorted entries.
- OCI Image Support: Build and push multi-platform Lambda images directly to a registry.
🚦 Quick Start
1. Initialize the project
uv sync
2. Run a Parallel Build
# Build with 4 parallel workers
uv run lambda-packer build --config package_config.yaml -j 4
3. Push to a Registry
Ensure you are logged into your registry (docker login), then run:
uv run lambda-packer build --config package_config.yaml --push
📖 Configuration (package_config.yaml)
The configuration supports absolute paths, allowing you to build Lambdas from other projects.
runtime_default: "python3.12"
layers:
# Shared layer from an external project
common-utils:
path: ./common
requirements: ./common/requirements.txt
platforms: [linux/amd64, linux/arm64]
lambdas:
# ZIP-based Lambda
api-handler:
path: ./lambdas/api
type: zip
layers: [common-utils]
platforms: [linux/amd64, linux/arm64]
# Image-based Lambda with custom tagging
processor:
path: ./samples/processor
type: image
image_tag: "my-registry.com/processor:{arch}"
handler: "app.handler"
layers: [common-utils]
platforms: [linux/amd64, linux/arm64]
💻 CLI Usage
build command
uv run lambda-packer build [OPTIONS]
Options:
--config PATH: Path to your config YAML (default:package_config.yaml).--dist PATH: Directory to store outputs (default:dist/).--cache STR: BuildKit cache options (e.g.,type=local,dest=.buildkit-cache).--push: Push OCI images to the registry.-j, --concurrency INT: Number of parallel builds (default: 1).
🏗 How it Works (Standardized Context)
The tool uses a "Staging Area" strategy to handle absolute paths and complex dependencies:
- Stage: A temporary directory is created for each build task.
- Map: Source code, requirements, and layers are copied/symlinked into standardized locations (
src/,layer_<name>/). - Compile: A multi-stage Dockerfile is generated to reference these fixed paths.
- Execute: BuildKit runs the build using this isolated staging directory as the context.
This ensures that only the necessary files are sent to Docker, making builds fast and independent of your local file structure.
🔒 Security & Determinism
All ZIP files are generated with a fixed timestamp (1980-01-01) and sorted file entries.
This ensures that if your code doesn't change, the SHA-256 hash of your ZIP file remains identical,
preventing unnecessary AWS Lambda deployments.
🛠 Development
Setup
git clone https://github.com/calvernaz/lambda-packer.git
cd lambda-packer
uv sync --extra dev
Running Tests
PYTHONPATH=src uv run pytest tests/
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambda_packer-0.1.62.tar.gz.
File metadata
- Download URL: lambda_packer-0.1.62.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
566ffb52c44780452d94f25647c8d46e36b942d4bfad20d7123da53f033f5a05
|
|
| MD5 |
ef7469e0082d59b20cbf965ad4c01d66
|
|
| BLAKE2b-256 |
e0f7de85f7577cd1fe72de39008184490cd90b82015d2a0413f1b85ed11aa85d
|
File details
Details for the file lambda_packer-0.1.62-py3-none-any.whl.
File metadata
- Download URL: lambda_packer-0.1.62-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfce4e0758d92e66c61d08b15b35392498ee87ca1f5ce77130dc2844cd6eb351
|
|
| MD5 |
273635797b28a90ae0ab549c1c7b8674
|
|
| BLAKE2b-256 |
0ba1f02712ea3875d79eee2a4157b6c6f51f958babe36781bcf400ad66e8354f
|