diff --git a/README.md b/README.md index d147b64..7f4daf7 100644 --- a/README.md +++ b/README.md @@ -422,6 +422,7 @@ No modules. | [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 | | [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 | | [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 | +| [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 | | [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 | | [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 | | [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. |
object({
parameter_names = list(string)
})
| `null` | no | diff --git a/main.tf b/main.tf index a041d53..b21ddbd 100644 --- a/main.tf +++ b/main.tf @@ -5,7 +5,7 @@ data "aws_partition" "current" {} locals { 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}" handler = var.package_type != "Zip" ? null : var.handler - publish = var.lambda_at_edge ? true : var.publish + publish = var.lambda_at_edge || var.snap_start ? true : var.publish runtime = var.package_type != "Zip" ? null : var.runtime timeout = var.lambda_at_edge ? min(var.timeout, 5) : var.timeout } @@ -69,6 +69,13 @@ resource "aws_lambda_function" "lambda" { subnet_ids = vpc_config.value.subnet_ids } } + + dynamic "snap_start" { + for_each = var.snap_start ? [true] : [] + content { + apply_on = "PublishedVersions" + } + } } // Copy of the original Lambda resource plus lifecycle configuration ignoring @@ -136,6 +143,13 @@ resource "aws_lambda_function" "lambda_external_lifecycle" { } } + dynamic "snap_start" { + for_each = var.snap_start ? [true] : [] + content { + apply_on = "PublishedVersions" + } + } + lifecycle { ignore_changes = [image_uri, last_modified, qualified_arn, qualified_invoke_arn, s3_object_version, version] } diff --git a/variables.tf b/variables.tf index 0daa2b1..48691c2 100644 --- a/variables.tf +++ b/variables.tf @@ -235,3 +235,9 @@ variable "iam_role_name" { default = null type = string } + +variable "snap_start" { + description = "Enable snap start settings for low-latency startups. This feature is currently only supported for `java11` and `java17` runtimes and `x86_64` architectures." + default = false + type = bool +}