Lambda Layer Basic
๐ฆ Overviewโ
This Terraform module provisions a basic AWS Lambda Layer, enabling code and dependency sharing across multiple Lambda functions. It helps you reduce duplication, improve modularity, and manage function sizes effectively.
โ Key Featuresโ
- Creates a Lambda Layer with versioning
- Accepts source archive from S3
- Supports compatible runtime declarations
- Tags for environment tracking and ownership
๐ผ Use Casesโ
- Share Python or Node.js libraries across functions
- Separate common logic from individual Lambda code
- Maintain versioned dependencies across environments
- Enable DRY (Don't Repeat Yourself) architecture
๐ฅ Input Variablesโ
| Name | Type | Description |
|---|---|---|
| region | string | AWS region to deploy the Lambda Layer |
| layer_name | string | Logical name for the Lambda Layer |
| s3_bucket | string | Name of the S3 bucket containing the zipped layer package |
| s3_key | string | Path to the ZIP file inside the S3 bucket |
| compatible_runtimes | list(string) | List of compatible Lambda runtimes (e.g., ["python3.11"]) |
| environment | string | Tag value for environment (e.g., dev, staging, prod) |
๐ค Outputsโ
| Name | Description |
|---|---|
| layer_name | The name of the created Lambda Layer |
| layer_arn | The ARN of the Lambda Layer version |
๐ Deployment Readinessโ
- โ Terraform 1.0+ compatible
- โ Uses AWS Provider 5.x+
- โ๏ธ Requires
lambda:PublishLayerVersionpermissions - ๐ฆ Zipped archive must be pre-uploaded to S3
๐ ๏ธ Example Usageโ
module "lambda_layer_basic_deployment" {
source = "git::ssh://git@github.com/archiphire/aws-level-1-modules.git//compute/lambda-layer-basic?ref=v1.0.0"
region = "us-east-1"
layer_name = "my-shared-layer"
s3_bucket = "my-layer-artifacts"
s3_key = "layers/shared-lib.zip"
compatible_runtimes = ["nodejs18.x"]
environment = "dev"
}
terraform init
terraform plan
terraform apply
or
tofu init
tofu plan
tofu apply
๐งน Cleanupโ
Terraform Destroy (Isolated Use):
terraform destroy
or
tofu destroy
Manual Deletion (Recommended for Production):
- Detach from functions before deletion
- Use AWS Console or CLI to delete the layer version
๐ก๏ธ Notesโ
This is a Level 1 compute module designed for reusable Lambda architecture.
For attaching layers to Lambda functions automatically, use this module with other Archiphire deployment patterns.
๐ Deployment Package Noticeโ
This module is part of the Level 1 AWS License Tier.
To access the full deployment package and source code, subscribe to Archiphire.