Skip to content

S3 Deployments

Compare
Choose a tag to compare
@moritzzimmer moritzzimmer released this 24 Aug 10:36

New Features

Enhanced the deployment module to support continuous deployment of Lambda functions packaged on S3.

Example:

locals {
  environment   = "production"
  function_name = "example-with-s3-codepipeline"
  s3_key        = "package/lambda.zip"
}

resource "aws_lambda_alias" "this" {
  function_name    = module.lambda.function_name
  function_version = module.lambda.version
  name             = local.environment

  lifecycle {
    ignore_changes = [function_version]
  }
}

module "deployment" {
  source = "moritzzimmer/lambda/aws//modules/deployment"

  alias_name    = aws_lambda_alias.this.name
  function_name = local.function_name
  s3_bucket     = aws_s3_bucket_object.source.bucket
  s3_key        = local.s3_key
}

module "lambda" {
  source        = "moritzzimmer/lambda/aws"

  function_name                    = local.function_name
  handler                          = "index.handler"
  ignore_external_function_updates = true
  publish                          = true
  runtime                          = "nodejs14.x"
  s3_bucket                        = aws_s3_bucket_object.source.bucket
  s3_key                           = local.s3_key
  s3_object_version                = aws_s3_bucket_object.source.version_id
}

resource "aws_s3_bucket" "source" {
  acl           = "private"
  bucket        = "source-bucket"
  force_destroy = true

  versioning {
    enabled = true
  }
}

resource "aws_s3_bucket_public_access_block" "source" {
  bucket = aws_s3_bucket.source.id

  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

see see example for details

Noteworthy

  • the dependency to external modules has been removed in favour of standard resources from the aws provider. Upgrading existing projects might result in Error: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it. errors. In this case run terraform apply again.
  • public access to the internal S3 bucket used for CodePipeline has been removed
  • container based deployments now publish a new version using update-function-code API call directly. The intermediate step with a wait function is not necessary anymore
  • upgraded to python 3.9 in CodeBuild
  • CodeDeploy environment (compute type, image and type) are now configurable

Special thanks

Thanks @thisismana for collaborating on this feature

What's Changed

  • feat: deployment pipeline for S3 based function packages by @moritzzimmer in #44

Full Changelog: v5.14.0...v5.15.0