Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiplesa committed Jan 11, 2025
1 parent a2d3444 commit a957c91
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ module "lambda_at_edge" {
handler = "index.handler"
event_type = "origin-response"
include_body = false
memory_size = 128
timeout = 3
}
}
Expand Down
2 changes: 2 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ usage: |2-
handler = "index.handler"
event_type = "origin-response"
include_body = false
memory_size = 128
timeout = 3
}
}
Expand Down
11 changes: 8 additions & 3 deletions examples/complete/lambda-at-edge.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -42,13 +44,17 @@ 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"
runtime = "nodejs16.x"
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 = {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions modules/lambda@edge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ module "lambda_at_edge" {
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| <a name="input_destruction_delay"></a> [destruction\_delay](#input\_destruction\_delay) | The delay, in [Golang ParseDuration](https://pkg.go.dev/time#ParseDuration) format, to wait before destroying the Lambda@Edge<br>functions.<br><br>This delay is meant to circumvent Lambda@Edge functions not being immediately deletable following their dissociation from<br>a CloudFront distribution, since they are replicated to CloudFront Edge servers around the world.<br><br>If set to `null`, no delay will be introduced.<br><br>By default, the delay is 20 minutes. This is because it takes about 3 minutes to destroy a CloudFront distribution, and<br>around 15 minutes until the Lambda@Edge function is available for deletion, in most cases.<br><br>For more information, see: https://github.com/hashicorp/terraform-provider-aws/issues/1721. | `string` | `"20m"` | no |
| <a name="input_memory_size"></a> [memory\_size](#input\_memory\_size) | Amount of memory in MB the Lambda Function can use at runtime. | `number` | `128` | no |
| <a name="input_timeout"></a> [timeout](#input\_timeout) | The amount of time the Lambda Function has to run in seconds. | `number` | `3` | no |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_functions"></a> [functions](#input\_functions) | Lambda@Edge functions to create.<br><br>The key of this map is the name label of the Lambda@Edge function.<br><br>`source.filename` and `source.content` dictate the name and content of the files that will make up the Lambda function<br>source, respectively.<br><br>`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)<br>resource.<br><br>`event_type` and `include_body` correspond to the attributes of the same name in the [Lambda Function association block<br>of the cloudfront\_distribution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#lambda-function-association)<br>resource. | <pre>map(object({<br> source = list(object({<br> filename = string<br> content = string<br> }))<br> runtime = string<br> handler = string<br> event_type = string<br> include_body = bool<br> }))</pre> | n/a | yes |
Expand Down
4 changes: 2 additions & 2 deletions modules/lambda@edge/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
14 changes: 2 additions & 12 deletions modules/lambda@edge/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ variable "functions" {
handler = string
event_type = string
include_body = bool
memory_size = optional(number)
timeout = optional(number)
}))

validation {
Expand Down Expand Up @@ -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
}

0 comments on commit a957c91

Please sign in to comment.