feat(cloudformation): carry DurableConfig and LoggingConfig through the SAM transform (#8101)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-12 09:10:13 -04:00
1 parent 8b31e7727c
commit 1e61e16056
3 files changed
+108 -1

No files matched your search

@@ -1847,8 +1847,12 @@ class SamTransformProcessor {
roleProps.set("AssumeRolePolicyDocument", assumePolicy);
ArrayNode managedPolicies = objectMapper.createArrayNode();
JsonNode durableConfig = properties.path("DurableConfig");
String basicPolicyArn = durableConfig.isObject() && !durableConfig.isEmpty()
? "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicDurableExecutionRolePolicy"
: "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole";
ObjectNode basicExecutionRole = objectMapper.createObjectNode();
basicExecutionRole.put("Fn::Sub", "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole");
basicExecutionRole.put("Fn::Sub", basicPolicyArn);
managedPolicies.add(basicExecutionRole);
JsonNode userPolicies = properties.path("Policies");
@@ -1907,6 +1911,8 @@ class SamTransformProcessor {
copyIfPresent(properties, "EphemeralStorage", lambdaProps);
copyIfPresent(properties, "VpcConfig", lambdaProps);
copyIfPresent(properties, "FileSystemConfigs", lambdaProps);
copyIfPresent(properties, "LoggingConfig", lambdaProps);
copyIfPresent(properties, "DurableConfig", lambdaProps);
JsonNode tracing = properties.path("Tracing");
if (!tracing.isMissingNode()) {
@@ -912,6 +912,56 @@ class SamTransformIntegrationTest {
.body("Configuration.Environment.Variables.STAGE", equalTo("local"));
}
@Test
void samDurableFunctionKeepsDurableAndLoggingConfig() {
String stackName = "sam-durable-stack";
stacksToDelete.add(stackName);
String template = """
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
LoggingConfig:
LogFormat: JSON
ApplicationLogLevel: DEBUG
Resources:
DurableFunc:
Type: AWS::Serverless::Function
Properties:
FunctionName: sam-durable-func
Handler: app.handler
Runtime: python3.13
InlineCode: "def handler(event, context): return event"
DurableConfig:
ExecutionTimeout: 60
RetentionPeriodInDays: 3
""";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateStack")
.formParam("StackName", stackName)
.formParam("TemplateBody", template)
.formParam("Capabilities.member.1", "CAPABILITY_IAM")
.when()
.post("/")
.then()
.statusCode(200);
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE");
given()
.when()
.get("/2015-03-31/functions/sam-durable-func")
.then()
.statusCode(200)
.body("Configuration.DurableConfig.ExecutionTimeout", equalTo(60))
.body("Configuration.DurableConfig.RetentionPeriodInDays", equalTo(3))
.body("Configuration.LoggingConfig.LogFormat", equalTo("JSON"))
.body("Configuration.LoggingConfig.ApplicationLogLevel", equalTo("DEBUG"));
}
@Test
void samSimpleTable_createsDynamoDbTable() {
String stackName = "sam-table-stack";
@@ -1117,6 +1117,57 @@ class SamTransformProcessorTest {
lambdaProps.path("FileSystemConfigs").get(0).path("LocalMountPath").asText());
}
@Test
void expandSamTemplate_durableFunctionKeepsDurableAndLoggingConfig() throws Exception {
JsonNode template = objectMapper.readTree("""
{
"Transform": "AWS::Serverless-2016-10-31",
"Globals": {
"Function": {
"LoggingConfig": {"LogFormat": "JSON", "ApplicationLogLevel": "DEBUG"}
}
},
"Resources": {
"DurableFn": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"Runtime": "python3.13",
"InlineCode": "def handler(e, c): return e",
"DurableConfig": {"ExecutionTimeout": 60, "RetentionPeriodInDays": 3}
}
},
"PlainFn": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"Runtime": "python3.13",
"InlineCode": "def handler(e, c): return e"
}
}
}
}
""");
JsonNode resources = processor.expandSamTemplate(template).path("Resources");
JsonNode durableProps = resources.path("DurableFn").path("Properties");
assertEquals(objectMapper.readTree("{\"ExecutionTimeout\": 60, \"RetentionPeriodInDays\": 3}"),
durableProps.path("DurableConfig"));
assertEquals(objectMapper.readTree("{\"LogFormat\": \"JSON\", \"ApplicationLogLevel\": \"DEBUG\"}"),
durableProps.path("LoggingConfig"));
assertEquals(objectMapper.readTree("""
[{"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicDurableExecutionRolePolicy"}]
"""), resources.path("DurableFnRole").path("Properties").path("ManagedPolicyArns"));
JsonNode plainProps = resources.path("PlainFn").path("Properties");
assertTrue(plainProps.path("DurableConfig").isMissingNode());
assertEquals("JSON", plainProps.path("LoggingConfig").path("LogFormat").asText());
assertEquals(objectMapper.readTree("""
[{"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"}]
"""), resources.path("PlainFnRole").path("Properties").path("ManagedPolicyArns"));
}
@Test
void expandSamTemplate_functionWithImageConfig() throws Exception {
// ImageConfig (EntryPoint/Command/WorkingDirectory overrides for a container-image