Skip to content

Commit 982d332

Browse files
feat: lambda snap_start argument (#104)
Co-authored-by: Moritz Zimmer <moritzzimmer@users.noreply.github.com>
1 parent eefa0a2 commit 982d332

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ No modules.
422422
| <a name="input_s3_bucket"></a> [s3\_bucket](#input\_s3\_bucket) | The S3 bucket location containing the function's deployment package. Conflicts with filename and image\_uri. This bucket must reside in the same AWS region where you are creating the Lambda function. | `string` | `null` | no |
423423
| <a name="input_s3_key"></a> [s3\_key](#input\_s3\_key) | The S3 key of an object containing the function's deployment package. Conflicts with filename and image\_uri. | `string` | `null` | no |
424424
| <a name="input_s3_object_version"></a> [s3\_object\_version](#input\_s3\_object\_version) | The object version containing the function's deployment package. Conflicts with filename and image\_uri. | `string` | `null` | no |
425+
| <a name="input_snap_start"></a> [snap\_start](#input\_snap\_start) | Enable snap start settings for low-latency startups. This feature is currently only supported for `java11` and `java17` runtimes and `x86_64` architectures. | `bool` | `false` | no |
425426
| <a name="input_sns_subscriptions"></a> [sns\_subscriptions](#input\_sns\_subscriptions) | Creates subscriptions to SNS topics which trigger your Lambda function. Required Lambda invocation permissions will be generated. | `map(any)` | `{}` | no |
426427
| <a name="input_source_code_hash"></a> [source\_code\_hash](#input\_source\_code\_hash) | Used to trigger updates. Must be set to a base64-encoded SHA256 hash of the package file specified with either filename or s3\_key. The usual way to set this is filebase64sha256('file.zip') where 'file.zip' is the local filename of the lambda function source archive. | `string` | `""` | no |
427428
| <a name="input_ssm"></a> [ssm](#input\_ssm) | List of AWS Systems Manager Parameter Store parameter names. The IAM role of this Lambda function will be enhanced with read permissions for those parameters. Parameters must start with a forward slash and can be encrypted with the default KMS key. | <pre>object({<br> parameter_names = list(string)<br> })</pre> | `null` | no |

main.tf

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ data "aws_partition" "current" {}
55
locals {
66
function_arn = "arn:${data.aws_partition.current.partition}:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:${var.function_name}"
77
handler = var.package_type != "Zip" ? null : var.handler
8-
publish = var.lambda_at_edge ? true : var.publish
8+
publish = var.lambda_at_edge || var.snap_start ? true : var.publish
99
runtime = var.package_type != "Zip" ? null : var.runtime
1010
timeout = var.lambda_at_edge ? min(var.timeout, 5) : var.timeout
1111
}
@@ -69,6 +69,13 @@ resource "aws_lambda_function" "lambda" {
6969
subnet_ids = vpc_config.value.subnet_ids
7070
}
7171
}
72+
73+
dynamic "snap_start" {
74+
for_each = var.snap_start ? [true] : []
75+
content {
76+
apply_on = "PublishedVersions"
77+
}
78+
}
7279
}
7380

7481
// Copy of the original Lambda resource plus lifecycle configuration ignoring
@@ -136,6 +143,13 @@ resource "aws_lambda_function" "lambda_external_lifecycle" {
136143
}
137144
}
138145

146+
dynamic "snap_start" {
147+
for_each = var.snap_start ? [true] : []
148+
content {
149+
apply_on = "PublishedVersions"
150+
}
151+
}
152+
139153
lifecycle {
140154
ignore_changes = [image_uri, last_modified, qualified_arn, qualified_invoke_arn, s3_object_version, version]
141155
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,9 @@ variable "iam_role_name" {
235235
default = null
236236
type = string
237237
}
238+
239+
variable "snap_start" {
240+
description = "Enable snap start settings for low-latency startups. This feature is currently only supported for `java11` and `java17` runtimes and `x86_64` architectures."
241+
default = false
242+
type = bool
243+
}

0 commit comments

Comments
 (0)