From a957c918c510cd7f023a247c6bb8398819667ba4 Mon Sep 17 00:00:00 2001 From: Mihai PLESA Date: Sat, 11 Jan 2025 09:45:36 +0000 Subject: [PATCH] fix --- README.md | 2 ++ README.yaml | 2 ++ examples/complete/lambda-at-edge.tf | 11 ++++++++--- modules/lambda@edge/README.md | 2 -- modules/lambda@edge/main.tf | 4 ++-- modules/lambda@edge/variables.tf | 14 ++------------ 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0ea07060..396dcf93 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,8 @@ module "lambda_at_edge" { handler = "index.handler" event_type = "origin-response" include_body = false + memory_size = 128 + timeout = 3 } } diff --git a/README.yaml b/README.yaml index 823d1def..17f23b51 100644 --- a/README.yaml +++ b/README.yaml @@ -357,6 +357,8 @@ usage: |2- handler = "index.handler" event_type = "origin-response" include_body = false + memory_size = 128 + timeout = 3 } } diff --git a/examples/complete/lambda-at-edge.tf b/examples/complete/lambda-at-edge.tf index ee6120aa..eca33a1c 100644 --- a/examples/complete/lambda-at-edge.tf +++ b/examples/complete/lambda-at-edge.tf @@ -34,6 +34,8 @@ module "lambda_at_edge" { handler = "index.handler" event_type = "viewer-request" include_body = false + memory_size = 128 + timeout = 3 }, # Add custom header to the response viewer_response = { @@ -42,6 +44,8 @@ module "lambda_at_edge" { handler = "index.handler" event_type = "viewer-response" include_body = false + memory_size = 128 + timeout = 3 }, origin_request = { source_zip = "origin-request.zip" @@ -49,6 +53,8 @@ module "lambda_at_edge" { handler = "index.handler" event_type = "origin-request" include_body = false + memory_size = 128 + timeout = 3 }, # Add security headers to the request from CF to the origin origin_response = { @@ -81,15 +87,14 @@ module "lambda_at_edge" { handler = "index.handler" event_type = "origin-response" include_body = false + memory_size = 128 + timeout = 3 } } # A destruction delay is always enabled due to automated tests (see variable description for more information). destruction_delay = "20m" - memory_size = 128 - timeout = 3 - providers = { aws = aws.us-east-1 } diff --git a/modules/lambda@edge/README.md b/modules/lambda@edge/README.md index 84708790..2b838c53 100644 --- a/modules/lambda@edge/README.md +++ b/modules/lambda@edge/README.md @@ -71,8 +71,6 @@ module "lambda_at_edge" { | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | | [destruction\_delay](#input\_destruction\_delay) | The delay, in [Golang ParseDuration](https://pkg.go.dev/time#ParseDuration) format, to wait before destroying the Lambda@Edge
functions.

This delay is meant to circumvent Lambda@Edge functions not being immediately deletable following their dissociation from
a CloudFront distribution, since they are replicated to CloudFront Edge servers around the world.

If set to `null`, no delay will be introduced.

By default, the delay is 20 minutes. This is because it takes about 3 minutes to destroy a CloudFront distribution, and
around 15 minutes until the Lambda@Edge function is available for deletion, in most cases.

For more information, see: https://github.com/hashicorp/terraform-provider-aws/issues/1721. | `string` | `"20m"` | no | -| [memory\_size](#input\_memory\_size) | Amount of memory in MB the Lambda Function can use at runtime. | `number` | `128` | no | -| [timeout](#input\_timeout) | The amount of time the Lambda Function has to run in seconds. | `number` | `3` | no | | [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no | | [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no | | [functions](#input\_functions) | Lambda@Edge functions to create.

The key of this map is the name label of the Lambda@Edge function.

`source.filename` and `source.content` dictate the name and content of the files that will make up the Lambda function
source, respectively.

`runtime` and `handler` correspond to the attributes of the same name in the [lambda\_function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function)
resource.

`event_type` and `include_body` correspond to the attributes of the same name in the [Lambda Function association block
of the cloudfront\_distribution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#lambda-function-association)
resource. |
map(object({
source = list(object({
filename = string
content = string
}))
runtime = string
handler = string
event_type = string
include_body = bool
}))
| n/a | yes | diff --git a/modules/lambda@edge/main.tf b/modules/lambda@edge/main.tf index 00a2bf21..514b6002 100644 --- a/modules/lambda@edge/main.tf +++ b/modules/lambda@edge/main.tf @@ -82,8 +82,8 @@ resource "aws_lambda_function" "default" { filename = each.value.source_zip != null ? data.local_file.lambda_zip[each.key].filename : data.archive_file.lambda_zip[each.key].output_path source_code_hash = each.value.source_zip != null ? sha256(data.local_file.lambda_zip[each.key].content_base64) : data.archive_file.lambda_zip[each.key].output_base64sha256 publish = true - memory_size = var.memory_size - timeout = var.timeout + memory_size = each.value.memory_size != null ? each.value.memory_size : 128 + timeout = each.value.timeout != null ? each.value.timeout : 3 } resource "aws_lambda_permission" "allow_cloudfront" { diff --git a/modules/lambda@edge/variables.tf b/modules/lambda@edge/variables.tf index 66e5c4b3..fb319075 100644 --- a/modules/lambda@edge/variables.tf +++ b/modules/lambda@edge/variables.tf @@ -31,6 +31,8 @@ variable "functions" { handler = string event_type = string include_body = bool + memory_size = optional(number) + timeout = optional(number) })) validation { @@ -62,15 +64,3 @@ variable "destruction_delay" { EOT default = "20m" } - -variable "memory_size" { - type = number - description = "Amount of memory in MB the Lambda Function can use at runtime." - default = 128 -} - -variable "timeout" { - type = number - description = "The amount of time the Lambda Function has to run in seconds." - default = 3 -}