Files
floci/compatibility-tests/compat-terraform/test/lambda-durable-config-tf/main.tf
T
TATSUNO “Taz” Yasuhiro ee2d1a68a6 feat(cloudformation): pass Lambda DurableConfig through (#5218)
* feat(cloudformation): pass Lambda DurableConfig through

AWS::Lambda::Function.DurableConfig reaches CreateFunction and
UpdateFunctionConfiguration. As on AWS, a RetentionPeriodInDays the
template leaves out is 14 on update too, a durable function created
without Timeout gets min(ExecutionTimeout, 900), and adding or removing
DurableConfig replaces the function.

* test(terraform): cover aws_lambda_function durable_config

The provider creates a durable function, reads it back without a diff,
updates execution_timeout in place, and before destroy stops a RUNNING
durable execution through ListDurableExecutionsByFunction,
StopDurableExecution and GetDurableExecution.

* fix(cloudformation): honor AWS::NoValue, cleared keys and large numbers in DurableConfig

A DurableConfig that Fn::If removes with AWS::NoValue leaves the
function plain. A KMSKeyArn the template leaves out or sets to "" clears
the key, as CloudFormation does on AWS, since Lambda keeps a stored key
when the update omits the member. A number beyond an integer reaches
Lambda unchanged, so its range check rejects it.

* fix(cloudformation): reject a DurableConfig that is not an object

Only an intrinsic that resolves to AWS::NoValue removes DurableConfig.
CloudFormation rejects a string, number or list in its schema check
before the function is touched, so an update with one no longer
replaces and deletes a durable function.

* test(cloudformation): cover Lambda DurableConfig with the AWS SDK

The CloudFormation and Lambda SDK clients create a durable function,
update DurableConfig in place, and remove it by replacing the function.

* fix(cloudformation): require ExecutionTimeout and known members in DurableConfig

CloudFormation checks DurableConfig against the schema on update too: an
update without ExecutionTimeout, or with a member the schema does not
list, fails before the function is touched. Floci let such an update
through and kept the old timeout.

* refactor(cloudformation): look up a Lambda function once per deploy

The name choice and the replacement decision now share one lookup and one
durable check, so they cannot disagree.
2026-10-07 12:39:36 -04:00

62 lines
1.8 KiB
Terraform

# aws_lambda_function.durable_config. The provider updates execution_timeout in place,
# and before it deletes the function it stops every RUNNING durable execution through
# ListDurableExecutionsByFunction, StopDurableExecution and GetDurableExecution.
variable "execution_timeout" {
type = number
default = 60
}
data "archive_file" "handler" {
type = "zip"
output_path = "${path.module}/handler.zip"
# Starts a long wait, so an execution stays RUNNING until something stops it.
source {
filename = "index.py"
content = <<-PY
import boto3
def handler(event, context):
if len(event["InitialExecutionState"]["Operations"]) == 1:
boto3.client("lambda").checkpoint_durable_execution(
DurableExecutionArn=event["DurableExecutionArn"],
CheckpointToken=event["CheckpointToken"],
Updates=[{"Id": "w", "Type": "WAIT", "SubType": "Wait", "Action": "START",
"WaitOptions": {"WaitSeconds": 600}}])
return {"Status": "PENDING"}
PY
}
}
resource "aws_iam_role" "durable" {
name = "floci-tf-lambda-durable"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = { Service = "lambda.amazonaws.com" }
Action = "sts:AssumeRole"
}]
})
}
resource "aws_lambda_function" "durable" {
function_name = "floci-tf-lambda-durable"
role = aws_iam_role.durable.arn
runtime = "python3.14"
handler = "index.handler"
filename = data.archive_file.handler.output_path
source_code_hash = data.archive_file.handler.output_base64sha256
timeout = 30
durable_config {
execution_timeout = var.execution_timeout
}
}
output "function_name" {
value = aws_lambda_function.durable.function_name
}