Skip to content

Commit 6ae1217

Browse files
mihaiplesagoruha
andauthored
memory and timeout vars for lambda@edge (#330)
* memory and timeout vars for lambda@edge * fix * fix * fix * fix * fix * fix * fix * fix * Update lambda-at-edge.tf * Update lambda-at-edge.tf --------- Co-authored-by: Igor Rodionov <[email protected]>
1 parent c95097f commit 6ae1217

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ module "lambda_at_edge" {
344344
}]
345345
runtime = "nodejs16.x"
346346
handler = "index.handler"
347+
memory_size = 128
348+
timeout = 3
347349
event_type = "origin-response"
348350
include_body = false
349351
}

README.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ usage: |2-
355355
}]
356356
runtime = "nodejs16.x"
357357
handler = "index.handler"
358+
memory_size = 128
359+
timeout = 3
358360
event_type = "origin-response"
359361
include_body = false
360362
}

examples/complete/lambda-at-edge.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module "lambda_at_edge" {
3232
}]
3333
runtime = "nodejs16.x"
3434
handler = "index.handler"
35+
memory_size = 128
36+
timeout = 3
3537
event_type = "viewer-request"
3638
include_body = false
3739
},
@@ -40,13 +42,17 @@ module "lambda_at_edge" {
4042
source_dir = "lib"
4143
runtime = "nodejs16.x"
4244
handler = "index.handler"
45+
memory_size = 128
46+
timeout = 3
4347
event_type = "viewer-response"
4448
include_body = false
4549
},
4650
origin_request = {
4751
source_zip = "origin-request.zip"
4852
runtime = "nodejs16.x"
4953
handler = "index.handler"
54+
memory_size = 128
55+
timeout = 3
5056
event_type = "origin-request"
5157
include_body = false
5258
},
@@ -79,6 +85,8 @@ module "lambda_at_edge" {
7985
}]
8086
runtime = "nodejs16.x"
8187
handler = "index.handler"
88+
memory_size = 128
89+
timeout = 3
8290
event_type = "origin-response"
8391
include_body = false
8492
}
@@ -92,4 +100,4 @@ module "lambda_at_edge" {
92100
}
93101

94102
context = module.this.context
95-
}
103+
}

modules/lambda@edge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module "lambda_at_edge" {
7373
| <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 |
7474
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
7575
| <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 |
76-
| <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 |
76+
| <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`, `handler`, `memory_size`, and `timeout` 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> memory_size = number<br> timeout = number<br> event_type = string<br> include_body = bool<br> }))</pre> | n/a | yes |
7777
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
7878
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
7979
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |

modules/lambda@edge/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ resource "aws_lambda_function" "default" {
7878
function_name = module.function_label[each.key].id
7979
runtime = each.value.runtime
8080
handler = each.value.handler
81+
memory_size = each.value.memory_size
82+
timeout = each.value.timeout
8183
role = module.role[each.key].arn
8284
filename = each.value.source_zip != null ? data.local_file.lambda_zip[each.key].filename : data.archive_file.lambda_zip[each.key].output_path
8385
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

modules/lambda@edge/variables.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ variable "functions" {
1313
1414
`source_zip` contains path to zip file with lambda source.
1515
16-
`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)
17-
resource.
16+
`runtime`, `handler`, `memory_size` and `timeout` correspond to the attributes of the same name in the [lambda_function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function)
17+
resource. See [here](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-at-edge-function-restrictions.html) for Lambda@Edge function restrictions.
1818
1919
`event_type` and `include_body` correspond to the attributes of the same name in the [Lambda Function association block
2020
of the cloudfront_distribution](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#lambda-function-association)
@@ -29,6 +29,8 @@ variable "functions" {
2929
source_zip = optional(string)
3030
runtime = string
3131
handler = string
32+
memory_size = optional(number, 128)
33+
timeout = optional(number, 3)
3234
event_type = string
3335
include_body = bool
3436
}))

0 commit comments

Comments
 (0)