Skip to main content

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โ€‹

NameTypeDescription
regionstringAWS region to deploy the Lambda Layer
layer_namestringLogical name for the Lambda Layer
s3_bucketstringName of the S3 bucket containing the zipped layer package
s3_keystringPath to the ZIP file inside the S3 bucket
compatible_runtimeslist(string)List of compatible Lambda runtimes (e.g., ["python3.11"])
environmentstringTag value for environment (e.g., dev, staging, prod)

๐Ÿ“ค Outputsโ€‹

NameDescription
layer_nameThe name of the created Lambda Layer
layer_arnThe ARN of the Lambda Layer version

๐Ÿš€ Deployment Readinessโ€‹

  • โœ… Terraform 1.0+ compatible
  • โœ… Uses AWS Provider 5.x+
  • โ˜๏ธ Requires lambda:PublishLayerVersion permissions
  • ๐Ÿ“ฆ 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.