fix(cloudformation): refuse a Lambda function property that is not an object (#5912)

* fix(cloudformation): refuse a Lambda function property that is not an object

The AWS::Lambda::Function provisioner read an object property that
resolved to a scalar or a list as absent, so a malformed VpcConfig,
DeadLetterConfig, TracingConfig or EphemeralStorage reset the function's
setting to its default instead of failing. Measured on CloudFormation
(eu-west-1, 2026-10-18): such a value fails the stack before the function
is touched, on create and on update, with "Property [VpcConfig] expected
type: JSONObject, found: String"; a list reads "found: JSONArray", and a
number or a boolean reads "found: String" too.

resolveMapOrDefault, which reads every object property of the function,
now refuses such a value with that message. AWS reports it from its
pre-deployment validation, with the detail in DescribeEvents, which Floci
does not model; the message is on the resource's failed event.

Tests: CloudFormationLambdaObjectPropertyIntegrationTest (a number VpcConfig
and a list DeadLetterConfig on create, a string TracingConfig on update that
keeps the setting) and, through the SDK, CloudFormationLambdaObjectPropertyTest;
both fail on main. The compatibility suite gains TestFixtures.awaitStackTerminal,
the same helper #5902 adds.

* fix(cloudformation): leave out a Lambda property that resolves to AWS::NoValue

Floci's template engine resolves Ref AWS::NoValue to an empty text node,
which the new type check refused as a String, so a valid template that
leaves VpcConfig, TracingConfig, DeadLetterConfig or EphemeralStorage out
through AWS::NoValue, directly or chosen by Fn::If, failed. Measured on
CloudFormation (eu-west-1, 2026-10-18): both stacks are created.
resolveMapOrDefault now resolves with resolveNodeOmittingNoValue, as other
provisioners do for optional properties, and reads what it leaves out as
the default.

Test: a direct Ref AWS::NoValue on VpcConfig and TracingConfig, and an
Fn::If choosing it for DeadLetterConfig, each create the stack; it fails
on the previous head.
This commit is contained in:
Alessandro Lattao authored and GitHub committed 2026-10-18 00:56:25 -04:00
1 parent 61102a7c4e
commit 30d2bf03d9
3 files changed
+275 -2

No files matched your search

@@ -818,14 +818,27 @@ public class LambdaCfnProvisioner implements CfnResourceProvisioner {
return values;
}
/**
* The object property {@code source}, or {@code defaultValue} when the template leaves it out,
* {@code Ref: AWS::NoValue} directly or through {@code Fn::If} included. Any other value is
* refused before the function is touched, with the message CloudFormation's property validation
* gives (measured in eu-west-1, 2026-10-18), where a number or a boolean reads as a String too.
*/
private Map<String, Object> resolveMapOrDefault(JsonNode props, String source,
CloudFormationTemplateEngine engine,
Map<String, Object> defaultValue) {
if (props == null || !props.has(source) || props.get(source).isNull()) {
return defaultValue;
}
JsonNode resolved = engine.resolveNode(props.get(source));
return resolved != null && resolved.isObject() ? jsonObjectToMap(resolved) : defaultValue;
JsonNode resolved = engine.resolveNodeOmittingNoValue(props.get(source));
if (resolved == null || resolved.isNull() || resolved.isMissingNode()) {
return defaultValue;
}
if (!resolved.isObject()) {
throw new AwsException("ValidationError", "Property [" + source + "] expected type: JSONObject, found: "
+ (resolved.isArray() ? "JSONArray" : "String"), 400);
}
return jsonObjectToMap(resolved);
}
private static Map<String, Object> mapWithNullValue(String key) {