AWS Lambda Layers: Size Limits, Best Practices & Setup Guide
Lambda Layers let you share libraries, binaries, and utilities across functions without bloating every deployment package. This guide covers size limits, creating layers, sharing them across functions and accounts, and when Container Images are the better choice.
Lambda Size Limits Summary
| Limit Type | Limit | Notes |
|---|---|---|
| Deployment package (unzipped) | 250MB | Includes function code + all layers combined |
| Deployment package (zipped, direct) | 50MB | For direct upload via CLI/console |
| Deployment package (via S3) | 250MB zipped | Use S3 for large packages |
| Layers per function | 5 | All layers share the 250MB unzipped budget |
| Layer ZIP (direct upload) | 50MB | Upload larger layers via S3 |
| Container image | 10GB | Bypasses all ZIP limits |
Creating a Lambda Layer
# Python layer: package dependencies correctly
# Layer structure: python/lib/python3.12/site-packages/
mkdir -p layer/python/lib/python3.12/site-packages
pip install requests boto3 pydantic \
--target layer/python/lib/python3.12/site-packages \
--platform manylinux2014_x86_64 \
--only-binary=:all:
# Create ZIP
cd layer && zip -r ../my-deps-layer.zip python/
cd ..
# Check size
ls -lh my-deps-layer.zip # Must be under 50MB for direct upload
# Publish layer
aws lambda publish-layer-version \
--layer-name my-python-deps \
--zip-file fileb://my-deps-layer.zip \
--compatible-runtimes python3.12 python3.11 \
--description "Common Python dependencies"
# Get layer ARN from output:
# "LayerVersionArn": "arn:aws:lambda:us-east-1:123456789:layer:my-python-deps:1" Attaching Layers to Functions
# Serverless Framework โ attach layers
functions:
api:
handler: src/handler.handler
layers:
- arn:aws:lambda:us-east-1:123456789:layer:my-python-deps:1
- arn:aws:lambda:us-east-1:123456789:layer:chromium:14
# AWS CDK โ attach layers
const depsLayer = lambda.LayerVersion.fromLayerVersionArn(
this,
'DepsLayer',
'arn:aws:lambda:us-east-1:123456789:layer:my-python-deps:1'
);
const fn = new lambda.Function(this, 'ApiFunction', {
runtime: lambda.Runtime.PYTHON_3_12,
handler: 'handler.lambda_handler',
code: lambda.Code.fromAsset('src'),
layers: [depsLayer],
});
# Node.js layer structure (for NODE_PATH resolution):
# nodejs/node_modules/
# nodejs/node20/node_modules/ (version-specific) Lambda Layers vs Container Images
| Factor | Lambda Layers | Container Images |
|---|---|---|
| Max size | 250MB unzipped | 10GB |
| Cold start | Faster (no image pull) | Slower (image pull on first cold start) |
| Build workflow | ZIP-based | Docker-based CI/CD |
| Custom runtime | Limited (provided.al2) | Any runtime |
| Best for | Shared libs, small binaries | Large deps, custom runtimes |
Related Products
on GumroadPremium Workflow Pack
Production-grade workflows, architecture guides, and deployment scripts for teams that ship. 10 advanced CI/CD workflows (blue-green, canary, E2E, security), 5 architecture deep-dives, code review checklist, PR process guide, and 5 battle-tested Bash deployment scripts.
Buy on Gumroad โGitHub Actions CI/CD Templates Pack
12 production-ready GitHub Actions workflow templates covering Node.js, Python, Docker, multi-environment deployments, security scanning, and auto-changelog. Copy, paste, ship.
Buy on Gumroad โDeveloper Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad โYou Might Also Need
AWS CDK Infrastructure as Code Guide
Complete AWS CDK guide for TypeScript/Python IaC. Learn constructs (L1/L2/L3), stacks, CDK Pipelines, diff/deploy workflow, and comparison with Terraform and CloudFormation.
Open free tool โ
AWS Lambda Cost Calculator
Estimate monthly AWS Lambda costs. Input invocations, duration, memory, and data transfer to get compute cost, request cost, and total with EC2 comparison.
Open free tool โ
AWS IAM Policy Generator
Visual AWS IAM policy JSON builder with action and resource selectors. Generate least-privilege IAM policies for S3, EC2, Lambda, DynamoDB, and more.
Open free tool โ
More Free Tools
Related Articles
AWS Lambda Cold Start Optimization: 10 Proven Techniques 2026
Eliminate or minimize AWS Lambda cold starts with 10 proven techniques: provisioned concurrency, SnapStart, package minimization, ARM Graviton2, lazy loading, and more with benchmark data.
Serverless vs Containers 2026: Lambda vs Docker Decision Guide
When should you use AWS Lambda vs Docker containers? This 2026 guide covers cost models, cold starts, use cases, hybrid architectures, and a decision flowchart to help you choose.
Cloud Deployment Tools in 2026: From Containers to Serverless
A practical guide to cloud deployment tools in 2026. Compare deployment strategies, container platforms, serverless frameworks, and GitOps workflows that enterprise teams use to ship software reliably.
Serverless vs Containers 2026: When to Use Each
Decision framework for choosing between serverless functions and containers in 2026. Cost analysis, cold start realities, architecture patterns, and the right tool for each workload type.
Serverless Cold Starts: How to Reduce Lambda Latency by 80%
Learn what causes AWS Lambda cold starts and how to reduce latency by 80%. Covers runtime comparison, Provisioned Concurrency, SnapStart, package optimization, and best practices.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- โก AI Code Review, Doc Generator & SQL Builder
- โก All premium templates & early access
- โก Member discounts on Gumroad products
$9/mo after trial ยท Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products โ grab them all at once and save big.
MIT licensed ยท Instant download ยท No subscription
See what's included โ Browse all deals โFrequently Asked Questions
What are AWS Lambda Layers?▼
Lambda Layers are a way to share code and dependencies across multiple Lambda functions without including them in each function's deployment package. A layer is a ZIP archive containing libraries, runtime code, or binaries. You can attach up to 5 layers per function, and each layer is extracted to the /opt directory in the Lambda execution environment. Layers reduce deployment package sizes and enable sharing common code across functions.
What are the size limits for Lambda Layers?▼
The unzipped size of a layer cannot exceed 250MB (the combined total of the function deployment package plus all attached layers must not exceed 250MB unzipped). Each layer ZIP file can be up to 50MB when uploaded directly, or up to 250MB when uploaded via S3. You can attach up to 5 layers per function. The 250MB unzipped limit is shared between your function code and all attached layers.
When should I use Lambda Layers vs Container Images?▼
Use Lambda Layers for sharing libraries across many small functions (node_modules, Python packages, shared utilities), binary dependencies (ffmpeg, chromium), and when you need fast deployments for application code changes. Use Container Images when your dependencies exceed 250MB, you need custom runtimes, or you want to use Docker-based CI/CD workflows. Container images support up to 10GB but have longer cold starts.
How do Lambda Layers interact with deployment packages?▼
Lambda extracts all layers to /opt/ in the execution environment before your function runs. For Node.js, add /opt/nodejs/node_modules to NODE_PATH. For Python, Lambda automatically includes /opt/python and /opt/python/lib/python3.x/site-packages in PYTHONPATH. Your function code can import from layers as if the libraries were installed locally. Layer code is available at runtime, not at build time.
Can I share Lambda Layers across AWS accounts?▼
Yes, Lambda Layers support resource-based policies that allow sharing across AWS accounts or making a layer publicly available. Use the add-layer-version-permission command to grant specific account IDs or all accounts (* for public) the lambda:GetLayerVersion permission. AWS also publishes managed layers for runtimes and popular libraries. Shared layers are useful in multi-account organizations to maintain a single source of truth for common dependencies.
What is the difference between Lambda Layers and Lambda Extensions?▼
Lambda Layers provide shared code and libraries extracted to /opt/. Lambda Extensions are a special type of layer that integrates with the Lambda lifecycle โ they can intercept initialization, invocation, and shutdown events. Extensions run in the same execution environment as the function and are used for monitoring agents, secret managers, and configuration providers. Both use the layer mechanism but serve different purposes.