Skip to content

0.4.0 Add `lambda_function_association` variable

Choose a tag to compare

@aknysh aknysh released this 04 Jan 17:25

what

  • Add lambda_function_association variable

why

  • To be able to trigger a lambda function with specific actions

example

module "cdn" {
  source                   = "../"
  namespace                = "eg"
  stage                    = "prod"
  name                     = "app"
  aliases                  = ["assets.cloudposse.com"]
  parent_zone_id           = "${aws_route53_zone.primary.zone_id}"
  use_regional_s3_endpoint = "true"
  origin_force_destroy     = "true"
  cors_allowed_headers     = ["*"]
  cors_allowed_methods     = ["GET", "HEAD", "PUT"]
  cors_allowed_origins     = ["*.cloudposse.com"]
  cors_expose_headers      = ["ETag"]
  lambda_function_association = [
    {
      event_type = "viewer-request"
      lambda_arn = "arn:aws:lambda:us-east-1:${var.account_id}:function:${local.func_name}:12"
    },
  ]
}

note

When using attributes of your own resource, the following error will be occurred.
https://stackoverflow.com/questions/52202672/terraform-lambda-function-association-for-cloudfront-as-optional-list-within-a-ma

example

  lambda_arn = "${aws_lambda_function.some-function.arn}:${aws_lambda_function.some-function.version}"

ref. hashicorp/terraform#16582

For the above reason, lambda_function_association must be defined directly in the current terraform version.