Skip to content

Latest commit

 

History

History

Complete example of blue/green deployments of Lambda functions

Creates a S3 packaged AWS Lambda function deployed using AWS CodePipeline, CodeBuild and CodeDeploy showcasing all available features:

  • custom deployment configurations to shift traffic to the new version and executes traffic hooks
  • before and after traffic hooks
  • rollback and CloudWatch alarms configuration
  • additional custom CodePipeline step executed after the deployment

usage

terraform init
terraform plan

Note that this example may create resources which cost money. Run terraform destroy to destroy those resources.

deploy

Upload a new zip package to S3 to start the deployment pipeline:

aws s3api put-object --bucket example-ci-{account_id}-{region} --key deployment-hooks/package/lambda.zip --body lambda.zip

Requirements

Name Version
terraform >= 1.3
archive >= 2.2
aws >= 5.32

Providers

Name Version
archive >= 2.2
aws >= 5.32

Modules

Name Source Version
deployment ../../../modules/deployment n/a
function ../../fixtures n/a
lambda ../../../ n/a
traffic_hook ../../../ n/a

Resources

Name Type
aws_cloudwatch_log_group.custom_step resource
aws_cloudwatch_metric_alarm.error_rate resource
aws_codebuild_project.custom_step resource
aws_codedeploy_deployment_config.canary resource
aws_iam_policy.codepipeline_execution resource
aws_iam_policy.custom_codepipeline_step resource
aws_iam_policy.traffic_hook resource
aws_iam_policy_attachment.codepipeline_execution resource
aws_iam_role.custom_codepipeline_step resource
aws_iam_role_policy_attachment.custom_codepipeline_step resource
aws_iam_role_policy_attachment.traffic_hook resource
aws_lambda_alias.this resource
aws_s3_bucket.source resource
aws_s3_bucket_notification.source resource
aws_s3_bucket_public_access_block.source resource
aws_s3_bucket_versioning.source resource
aws_s3_object.initial resource
archive_file.traffic_hook data source
aws_caller_identity.current data source
aws_iam_policy_document.codepipeline_execution data source
aws_iam_policy_document.custom_codepipeline_step data source
aws_iam_policy_document.traffic_hook data source
aws_region.current data source

Inputs

Name Description Type Default Required
region n/a string "eu-west-1" no

Outputs

No outputs.