Skip to content

Commit

Permalink
feat: lambda snap_start argument (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Moritz Zimmer <[email protected]>
  • Loading branch information
dimitriydotsenko and moritzzimmer authored Nov 17, 2023
1 parent eefa0a2 commit 982d332
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ No modules.
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
16 changes: 15 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 982d332

Please sign in to comment.