fix(cloudformation): keep a rule target's dead-letter queue, retry policy, role and ECS parameters (#5958)

* fix(cloudformation): keep a rule target's dead-letter queue, retry policy, role and ECS parameters

EventsCfnProvisioner built each AWS::Events::Rule target from Id, Arn, the
inputs, HttpParameters, SqsParameters and BatchParameters only. A target's
DeadLetterConfig and RetryPolicy were dropped, so ListTargetsByRule showed
neither, delivery ran on the defaults (185 attempts over 24 hours) and an
event the target could not take was logged and lost instead of reaching the
queue the stack declared. RoleArn and EcsParameters, which PutTargets keeps,
were dropped as well.

Targets set through PutTargets already get the delivery semantics from
TargetDispatcher, so the provisioner now passes the four members through,
validated by putTargets as the API validates them. EcsParameters is converted
to the API's shape: the resource schema spells AwsVpcConfiguration,
PlacementStrategies, TagList and the placement and capacity provider items
differently from the EventBridge API, which spells them awsvpcConfiguration,
PlacementStrategy, Tags and in camel case; ListTargetsByRule on AWS returns
the converted shape (measured). RoleArn is stored, not used for delivery, as
Floci does not invoke targets under the role.

Targets is resolved once, with the engine's resolveNodeOmittingNoValue, so an
Fn::If choosing the whole list works, and a member, a list item or an Fn::If
branch that is AWS::NoValue is left out of the call while a literal "" stays.
An earlier version marked AWS::NoValue itself before resolving, with a
sentinel; the engine's rule does the same without one.

The four members are read against the types AWS::Events::Rule's resource
schema gives them, before the rule exists, with the messages measured on
CloudFormation (eu-west-1): template validation's "Property
[MaximumRetryAttempts] expected type: Integer, found: Float", and the
handler's "Model validation failed (#/Targets/0/EcsParameters/
EnableECSManagedTags: expected type: Boolean, found: String)" for what only
the handler refuses, which waits until every target has passed template
validation, as on AWS. What CloudFormation converts is converted the same
way: "4" is 4, "TRUE" is true, 5 in a list of strings is "5". Reading them
with convertValue alone truncated 4.5 to 4, ignored a RetryPolicy given as a
string and failed on "abc" with Jackson's message.

A list of strings (Subnets, SecurityGroups) takes every form that yields a
list on AWS, as Lambda's list properties do since #5923 and #5949: a Ref to a
CommaDelimitedList, Fn::Split and an Fn::If choosing either, also inside an
EcsParameters an Fn::If chooses; a Ref to a String is refused (measured).
That is why the reader walks the template as written, with the engine's
omitNoValue, now public, and resolves each call it meets, instead of
checking the resolved tree, where a CommaDelimitedList is already text.

The check is the new CfnPropertyTypes, which also takes over
LambdaCfnProvisioner's requireType and its list-of-strings reading, so
template validation has one implementation for both provisioners.

* test(cloudformation): read the rule's only target without List.getFirst

The SDK compatibility tests compile for Java 17, which has no
List.getFirst; the image build of sdk-test-java and ec2-containers failed
on it. A local JDK 25 with source 17 does not check the API, so the class
was compiled again with --release 17.

* test(compat): wait for a stack 50 ms at a time against Floci

Review of #5958: TestFixtures.awaitStackTerminal slept 500 ms between
checks, so each stack, which Floci finishes in milliseconds, cost at least
half a second. It now checks every 50 ms against Floci, as the integration
tests' CfnStackWaits does, and keeps 500 ms against real AWS. The rule
target test waits 10 seconds for a stack against Floci instead of 60, and
10 minutes against AWS, where the queues take minutes.
This commit is contained in:
Alessandro Lattao authored and GitHub committed 2026-10-18 22:05:03 -04:00
1 parent 6027872078
commit d60c973865
10 files changed
+1261 -91

No files matched your search

@@ -280,7 +280,7 @@ public class CloudFormationTemplateEngine {
if (node.has("Fn::Split") || node.has("Fn::GetAZs") || node.has("Fn::Cidr")) {
return objectMapper.valueToTree(resolveList(node));
}
if (isIntrinsic(node) || node.has(GET_STACK_OUTPUT)) {
if (callsIntrinsic(node)) {
return TextNode.valueOf(resolve(node));
}
// Plain object: resolve each field.
@@ -307,7 +307,14 @@ public class CloudFormationTemplateEngine {
return resolveNode(omitNoValue(node));
}
private JsonNode omitNoValue(JsonNode node) {
/**
* The template node with every {@code AWS::NoValue} that stands for a member, a list item or an
* {@code Fn::If} branch left out, and every {@code Fn::If} outside another function replaced by
* the branch its condition chooses; other intrinsic calls stay as they are, unresolved. A
* {@link MissingNode} when the node itself is {@code AWS::NoValue}. A caller that needs to see how
* a member is written, a literal or a call, reads it from here before resolving it.
*/
public JsonNode omitNoValue(JsonNode node) {
if (node == null || node.isNull() || node.isMissingNode()) {
return node;
}
@@ -348,6 +355,14 @@ public class CloudFormationTemplateEngine {
return node;
}
/**
* Whether {@code node} calls an intrinsic function, which {@link #resolveNode} evaluates, rather
* than being a literal object whose fields it resolves one by one.
*/
public static boolean callsIntrinsic(JsonNode node) {
return node.isObject() && (isIntrinsic(node) || node.has(GET_STACK_OUTPUT));
}
private static boolean isIntrinsic(JsonNode node) {
return node.has("Ref") || node.has("Fn::Sub") || node.has("Fn::Join")
|| node.has("Fn::Select") || node.has("Fn::Base64") || node.has("Fn::GetAtt")
@@ -0,0 +1,278 @@
package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.BooleanNode;
import com.fasterxml.jackson.databind.node.IntNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
/**
* CloudFormation's checks of a property value against the type the resource schema declares, with
* the messages they give (measured in eu-west-1, 2026-10-18).
*
* <p>Template validation runs over the whole template before any resource is touched and names the
* property, or the list index, alone: "Property [Layers] expected type: JSONArray, found: String".
* Where an object or a list is expected, a number or a boolean reads as a String. Where text is
* expected, any scalar is taken as its text. Where an integer is expected, a whole number or text
* that spells one is taken, and anything else is named by what it is: Float (4.5 or "4.5"),
* Boolean, String, JSONObject, JSONArray. Where a boolean is expected, only an object or a list is
* refused there. A list of strings also takes every intrinsic that yields a list, as
* {@link #readStringList} says.
*
* <p>The resource handler's model validation runs after it, on the values CloudFormation converted,
* and names the whole path: a boolean that is not true or false in any case, and an integer beyond
* 32 bits, fail as "Model validation failed (#/Targets/0/EcsParameters/EnableECSManagedTags:
* expected type: Boolean, found: String)".
*/
final class CfnPropertyTypes {
/** A type a resource schema declares for a property. */
enum Kind {
STRING("String"), INTEGER("Integer"), BOOLEAN("Boolean"), OBJECT("JSONObject"), LIST("JSONArray");
private final String schemaName;
Kind(String schemaName) {
this.schemaName = schemaName;
}
}
/** A property's type: a scalar, an object with the members it declares, or a list of {@code items}. */
record Type(Kind kind, Map<String, Type> members, Type items) {
static final Type STRING = new Type(Kind.STRING, null, null);
static final Type INTEGER = new Type(Kind.INTEGER, null, null);
static final Type BOOLEAN = new Type(Kind.BOOLEAN, null, null);
static Type object(Map<String, Type> members) {
return new Type(Kind.OBJECT, members, null);
}
static Type list(Type items) {
return new Type(Kind.LIST, null, items);
}
}
private static final Pattern WHOLE_NUMBER = Pattern.compile("-?\\d+");
private static final String INTEGER_RANGE_HINT = ". This may occur when a numeric value exceeds 32-bit"
+ " integer max (2147483647). Consider using 'number' type or ensure value fits in integer range.";
private CfnPropertyTypes() {
}
/**
* Refuses a value of another type than {@code expected}, an object or a list, with template
* validation's message, where a number or a boolean reads as a String.
*/
static void requireType(String property, JsonNode value, JsonNodeType expected) {
if (value.getNodeType() != expected) {
throw templateMismatch(property, expected == JsonNodeType.OBJECT ? Kind.OBJECT : Kind.LIST,
containerName(value));
}
}
/**
* The list-of-strings property written as {@code raw} in the template, or null when it is
* {@code Ref: AWS::NoValue}, directly or through {@code Fn::If}. A literal of another type is
* refused (see {@link #requireType}), and so is an intrinsic that yields a string (see
* {@link CloudFormationTemplateEngine#yieldsString}). Any other intrinsic is read through
* {@link CloudFormationTemplateEngine#resolveStringList}, as CloudFormation reads a {@code Ref}
* to a {@code CommaDelimitedList} parameter, which the engine resolves to the comma-joined text,
* and {@code Fn::Split} (measured, eu-west-1, 2026-10-18).
*/
static List<String> readStringList(String property, JsonNode raw, CloudFormationTemplateEngine engine) {
if (raw.isValueNode()) {
requireType(property, raw, JsonNodeType.ARRAY);
}
if (raw.isObject()) {
JsonNode resolved = engine.resolveNodeOmittingNoValue(raw);
if (resolved == null || resolved.isNull() || resolved.isMissingNode()) {
return null;
}
if (resolved.isObject() || (!resolved.isArray() && engine.yieldsString(raw))) {
requireType(property, resolved, JsonNodeType.ARRAY);
}
}
return engine.resolveStringList(raw);
}
/**
* Reads template values against their declared types and resolves them, converting them as
* CloudFormation does before the handler sees them: an integer or a boolean given as text
* becomes one, and a number or a boolean where text is expected becomes text. Members a type
* does not declare are resolved as they are. What {@code AWS::NoValue} stands for is left out.
* Template validation failures are thrown at once; the first model validation failure waits for
* {@link #finish}, so every value read has passed template validation first, as on AWS.
*/
static final class Reader {
private final CloudFormationTemplateEngine engine;
private AwsException modelFailure;
Reader(CloudFormationTemplateEngine engine) {
this.engine = engine;
}
/**
* The template value {@code raw}, at {@code path} in the resource's properties, read as
* {@code type}; null when it is absent or {@code AWS::NoValue}.
*/
JsonNode read(String path, JsonNode raw, Type type) {
return read(path, path.substring(path.lastIndexOf('/') + 1), engine.omitNoValue(raw), type);
}
/** Throws the first model validation failure found by {@link #read}, if any. */
void finish() {
if (modelFailure != null) {
throw modelFailure;
}
}
private JsonNode read(String path, String property, JsonNode raw, Type type) {
if (raw == null || raw.isNull() || raw.isMissingNode()) {
return null;
}
if (type.kind() == Kind.LIST && type.items().kind() == Kind.STRING) {
return readStringList(property, raw);
}
JsonNode value = raw.isContainerNode() && !CloudFormationTemplateEngine.callsIntrinsic(raw)
? raw : engine.resolveNode(raw);
if (value == null || value.isNull() || value.isMissingNode()) {
return null;
}
return switch (type.kind()) {
case OBJECT -> readObject(path, property, value, type.members());
case LIST -> readList(path, property, value, type.items());
case STRING -> readString(property, value);
case INTEGER -> readInteger(path, property, value);
case BOOLEAN -> readBoolean(path, property, value);
};
}
private JsonNode readObject(String path, String property, JsonNode value, Map<String, Type> members) {
requireType(property, value, JsonNodeType.OBJECT);
ObjectNode out = JsonNodeFactory.instance.objectNode();
for (Map.Entry<String, JsonNode> member : value.properties()) {
Type memberType = members.get(member.getKey());
JsonNode read = memberType == null ? engine.resolveNode(member.getValue())
: read(path + "/" + member.getKey(), member.getKey(), member.getValue(), memberType);
if (read != null) {
out.set(member.getKey(), read);
}
}
return out;
}
private JsonNode readList(String path, String property, JsonNode value, Type items) {
requireType(property, value, JsonNodeType.ARRAY);
ArrayNode out = JsonNodeFactory.instance.arrayNode();
for (int i = 0; i < value.size(); i++) {
JsonNode read = read(path + "/" + i, String.valueOf(i), value.get(i), items);
if (read != null) {
out.add(read);
}
}
return out;
}
/** A literal item that is an object or a list is refused by its index, as for any string. */
private JsonNode readStringList(String property, JsonNode raw) {
if (raw.isArray()) {
for (int i = 0; i < raw.size(); i++) {
JsonNode item = raw.get(i);
if (item.isContainerNode() && !CloudFormationTemplateEngine.callsIntrinsic(item)) {
throw templateMismatch(String.valueOf(i), Kind.STRING, containerName(item));
}
}
}
List<String> values = CfnPropertyTypes.readStringList(property, raw, engine);
if (values == null) {
return null;
}
ArrayNode out = JsonNodeFactory.instance.arrayNode();
values.forEach(out::add);
return out;
}
private static JsonNode readString(String property, JsonNode value) {
if (value.isContainerNode()) {
throw templateMismatch(property, Kind.STRING, containerName(value));
}
return value.isTextual() ? value : TextNode.valueOf(value.asText());
}
private JsonNode readInteger(String path, String property, JsonNode value) {
String text = value.isIntegralNumber() ? value.bigIntegerValue().toString() : value.asText();
if (value.isContainerNode() || value.isBoolean() || !WHOLE_NUMBER.matcher(text).matches()) {
throw templateMismatch(property, Kind.INTEGER, scalarName(value));
}
BigDecimal number = new BigDecimal(text);
if (number.compareTo(BigDecimal.valueOf(Integer.MIN_VALUE)) < 0
|| number.compareTo(BigDecimal.valueOf(Integer.MAX_VALUE)) > 0) {
recordModelFailure(path, Kind.INTEGER, INTEGER_RANGE_HINT);
return value;
}
return IntNode.valueOf(number.intValue());
}
private JsonNode readBoolean(String path, String property, JsonNode value) {
if (value.isContainerNode()) {
throw templateMismatch(property, Kind.BOOLEAN, containerName(value));
}
String text = value.asText();
if ("true".equalsIgnoreCase(text) || "false".equalsIgnoreCase(text)) {
return BooleanNode.valueOf(Boolean.parseBoolean(text));
}
recordModelFailure(path, Kind.BOOLEAN, "");
return value;
}
private void recordModelFailure(String path, Kind expected, String hint) {
if (modelFailure == null) {
modelFailure = new AwsException("InvalidRequest", "Model validation failed (#/" + path
+ ": expected type: " + expected.schemaName + ", found: String" + hint + ")", 400);
}
}
}
private static AwsException templateMismatch(String property, Kind expected, String found) {
return new AwsException("ValidationError", "Property [" + property + "] expected type: "
+ expected.schemaName + ", found: " + found, 400);
}
private static String containerName(JsonNode value) {
return switch (value.getNodeType()) {
case OBJECT -> "JSONObject";
case ARRAY -> "JSONArray";
default -> "String";
};
}
/** What template validation calls a value that is not a whole number where an integer is expected. */
private static String scalarName(JsonNode value) {
if (value.isContainerNode()) {
return containerName(value);
}
if (value.isBoolean()) {
return "Boolean";
}
if (value.isNumber()) {
return "Float";
}
try {
new BigDecimal(value.asText());
return "Float";
} catch (NumberFormatException notANumber) {
return "String";
}
}
}
@@ -9,9 +9,11 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnPropertyTypes.Type;
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
import io.github.hectorvent.floci.services.eventbridge.model.ApiDestination;
import io.github.hectorvent.floci.services.eventbridge.model.BatchParameters;
import io.github.hectorvent.floci.services.eventbridge.model.EcsParameters;
import io.github.hectorvent.floci.services.eventbridge.model.EventBus;
import io.github.hectorvent.floci.services.eventbridge.model.HttpParameters;
import io.github.hectorvent.floci.services.eventbridge.model.InputTransformer;
@@ -51,6 +53,38 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
private static final Logger LOG = Logger.getLogger(EventsCfnProvisioner.class);
private static final ObjectMapper MAPPER = new ObjectMapper();
/**
* The types AWS::Events::Rule's resource schema gives the target members this provisioner reads
* as typed values (describe-type, eu-west-1, 2026-10-18), in the template's spelling.
*/
private static final Type ECS_PARAMETERS = Type.object(Map.ofEntries(
Map.entry("CapacityProviderStrategy", Type.list(Type.object(Map.of(
"CapacityProvider", Type.STRING, "Base", Type.INTEGER, "Weight", Type.INTEGER)))),
Map.entry("EnableECSManagedTags", Type.BOOLEAN),
Map.entry("EnableExecuteCommand", Type.BOOLEAN),
Map.entry("Group", Type.STRING),
Map.entry("LaunchType", Type.STRING),
Map.entry("NetworkConfiguration", Type.object(Map.of("AwsVpcConfiguration", Type.object(Map.of(
"AssignPublicIp", Type.STRING,
"SecurityGroups", Type.list(Type.STRING),
"Subnets", Type.list(Type.STRING)))))),
Map.entry("PlacementConstraints", Type.list(Type.object(Map.of(
"Expression", Type.STRING, "Type", Type.STRING)))),
Map.entry("PlacementStrategies", Type.list(Type.object(Map.of(
"Field", Type.STRING, "Type", Type.STRING)))),
Map.entry("PlatformVersion", Type.STRING),
Map.entry("PropagateTags", Type.STRING),
Map.entry("ReferenceId", Type.STRING),
Map.entry("TagList", Type.list(Type.object(Map.of("Key", Type.STRING, "Value", Type.STRING)))),
Map.entry("TaskCount", Type.INTEGER),
Map.entry("TaskDefinitionArn", Type.STRING)));
private static final Type TARGETS = Type.list(Type.object(Map.of(
"RoleArn", Type.STRING,
"RetryPolicy", Type.object(Map.of(
"MaximumRetryAttempts", Type.INTEGER, "MaximumEventAgeInSeconds", Type.INTEGER)),
"DeadLetterConfig", Type.object(Map.of("Arn", Type.STRING)),
"EcsParameters", ECS_PARAMETERS)));
private static final String EVENT_BUS_CREATED_TIME_ATTR = "FlociEventBusCreatedTime";
private static final String EVENT_BUS_MANAGED_TAG_KEYS_ATTR = "FlociEventBusManagedTagKeys";
private static final String EVENT_BUS_MANAGED_POLICY_ATTR = "FlociEventBusManagedPolicy";
@@ -143,6 +177,10 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
String stateStr = ctx.resolveOptional(props, "State");
RuleState state = "DISABLED".equals(stateStr) ? RuleState.DISABLED : RuleState.ENABLED;
// Read before the rule exists, as CloudFormation refuses a target of the wrong type before it
// touches the rule.
List<Target> targets = declaredTargets(props, ctx);
Rule rule = eventBridgeService.putRule(ruleName, busName, eventPattern, scheduleExpression,
state, description, roleArn, Map.of(), ctx.region());
r.setPhysicalId(ruleName);
@@ -154,49 +192,6 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
r.getAttributes().put("EventBusName", busName);
}
// Provision inline targets
List<Target> targets = new ArrayList<>();
if (props != null && props.has("Targets") && props.get("Targets").isArray()) {
for (JsonNode targetNode : props.get("Targets")) {
JsonNode resolved = ctx.engine().resolveNode(targetNode);
String targetId = resolved.path("Id").asText(null);
String targetArn = resolved.path("Arn").asText(null);
String input = resolved.path("Input").asText(null);
String inputPath = resolved.path("InputPath").asText(null);
if (targetId != null && targetArn != null) {
Target target = new Target(targetId, targetArn, input, inputPath);
target.setInputTransformer(InputTransformer.fromJson(resolved.path("InputTransformer")));
JsonNode httpParamsNode = resolved.path("HttpParameters");
if (httpParamsNode.isObject()) {
target.setHttpParameters(MAPPER.convertValue(httpParamsNode, HttpParameters.class));
}
JsonNode sqsParamsNode = resolved.path("SqsParameters");
if (!sqsParamsNode.isMissingNode() && sqsParamsNode.isObject()) {
String messageGroupId = sqsParamsNode.path("MessageGroupId").asText(null);
if (messageGroupId != null) {
SqsParameters sqsParameters = new SqsParameters();
sqsParameters.setMessageGroupId(messageGroupId);
target.setSqsParameters(sqsParameters);
}
}
JsonNode batchParamsNode = resolved.path("BatchParameters");
if (!batchParamsNode.isMissingNode() && batchParamsNode.isObject()) {
JsonNode arrayProperties = batchParamsNode.path("ArrayProperties");
BatchParameters batchParameters = new BatchParameters();
batchParameters.setJobDefinition(batchParamsNode.path("JobDefinition").asText(null));
batchParameters.setJobName(batchParamsNode.path("JobName").asText(null));
if (arrayProperties.isObject()) {
batchParameters.setArrayProperties(jsonObjectToMap(arrayProperties));
}
if (batchParamsNode.has("RetryStrategy")) {
batchParameters.setRetryStrategy(batchParamsNode.get("RetryStrategy"));
}
target.setBatchParameters(batchParameters);
}
targets.add(target);
}
}
}
if (ctx.isUpdate()) {
snapshotTargetsBeforeUpdate(r, ruleName, busName, ctx.region());
}
@@ -211,6 +206,80 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
}
}
/**
* The rule's {@code Targets}, each carrying what PutTargets would set. An Fn::If that chooses the
* whole list works, and AWS::NoValue is left out wherever it stands for a member, a list item or
* an Fn::If branch, as CloudFormation leaves them out of the PutTargets call, while a literal ""
* stays. The members typed in {@link #TARGETS} are read against the resource schema's types; the
* others are resolved as they come.
*/
private List<Target> declaredTargets(JsonNode props, ProvisionContext ctx) {
List<Target> targets = new ArrayList<>();
if (props == null || !props.has("Targets")) {
return targets;
}
CfnPropertyTypes.Reader types = new CfnPropertyTypes.Reader(ctx.engine());
JsonNode targetNodes = types.read("Targets", props.get("Targets"), TARGETS);
types.finish();
if (targetNodes == null || !targetNodes.isArray()) {
return targets;
}
for (JsonNode resolved : targetNodes) {
String targetId = resolved.path("Id").asText(null);
String targetArn = resolved.path("Arn").asText(null);
String input = resolved.path("Input").asText(null);
String inputPath = resolved.path("InputPath").asText(null);
if (targetId == null || targetArn == null) {
continue;
}
Target target = new Target(targetId, targetArn, input, inputPath);
target.setInputTransformer(InputTransformer.fromJson(resolved.path("InputTransformer")));
JsonNode httpParamsNode = resolved.path("HttpParameters");
if (httpParamsNode.isObject()) {
target.setHttpParameters(MAPPER.convertValue(httpParamsNode, HttpParameters.class));
}
JsonNode sqsParamsNode = resolved.path("SqsParameters");
if (!sqsParamsNode.isMissingNode() && sqsParamsNode.isObject()) {
String messageGroupId = sqsParamsNode.path("MessageGroupId").asText(null);
if (messageGroupId != null) {
SqsParameters sqsParameters = new SqsParameters();
sqsParameters.setMessageGroupId(messageGroupId);
target.setSqsParameters(sqsParameters);
}
}
JsonNode batchParamsNode = resolved.path("BatchParameters");
if (!batchParamsNode.isMissingNode() && batchParamsNode.isObject()) {
JsonNode arrayProperties = batchParamsNode.path("ArrayProperties");
BatchParameters batchParameters = new BatchParameters();
batchParameters.setJobDefinition(batchParamsNode.path("JobDefinition").asText(null));
batchParameters.setJobName(batchParamsNode.path("JobName").asText(null));
if (arrayProperties.isObject()) {
batchParameters.setArrayProperties(jsonObjectToMap(arrayProperties));
}
if (batchParamsNode.has("RetryStrategy")) {
batchParameters.setRetryStrategy(batchParamsNode.get("RetryStrategy"));
}
target.setBatchParameters(batchParameters);
}
target.setRoleArn(resolved.path("RoleArn").asText(null));
JsonNode ecsParamsNode = resolved.path("EcsParameters");
if (ecsParamsNode.isObject()) {
target.setEcsParameters(MAPPER.convertValue(
ecsParametersInApiShape(ecsParamsNode), EcsParameters.class));
}
JsonNode retryPolicyNode = resolved.path("RetryPolicy");
if (retryPolicyNode.isObject()) {
target.setRetryPolicy(MAPPER.convertValue(retryPolicyNode, Target.RetryPolicy.class));
}
JsonNode deadLetterConfigNode = resolved.path("DeadLetterConfig");
if (deadLetterConfigNode.isObject()) {
target.setDeadLetterConfig(MAPPER.convertValue(deadLetterConfigNode, Target.DeadLetterConfig.class));
}
targets.add(target);
}
return targets;
}
/**
* Records the targets the rule carries before this update reconciles them, so they can be put
* back when the stack update fails: by {@link #restoreTargetsAfterFailedUpdate} when this
@@ -831,6 +900,44 @@ public class EventsCfnProvisioner implements CfnResourceProvisioner {
"ResourceNotFoundException");
}
/**
* A template's {@code EcsParameters} in the shape PutTargets takes. The resource schema
* capitalizes members the EventBridge API spells in camel case ({@code AwsVpcConfiguration},
* the placement and capacity provider items) and names two lists differently
* ({@code PlacementStrategies}, {@code TagList}); the rest is the same.
*/
private static ObjectNode ecsParametersInApiShape(JsonNode template) {
ObjectNode api = template.deepCopy();
rename(api, "PlacementStrategies", "PlacementStrategy");
rename(api, "TagList", "Tags");
if (api.get("NetworkConfiguration") instanceof ObjectNode network) {
rename(network, "AwsVpcConfiguration", "awsvpcConfiguration");
}
renameInItems(api.get("PlacementStrategy"), Map.of("Type", "type", "Field", "field"));
renameInItems(api.get("PlacementConstraints"), Map.of("Type", "type", "Expression", "expression"));
renameInItems(api.get("CapacityProviderStrategy"),
Map.of("CapacityProvider", "capacityProvider", "Weight", "weight", "Base", "base"));
return api;
}
private static void renameInItems(JsonNode items, Map<String, String> names) {
if (items == null || !items.isArray()) {
return;
}
for (JsonNode item : items) {
if (item instanceof ObjectNode object) {
names.forEach((from, to) -> rename(object, from, to));
}
}
}
private static void rename(ObjectNode node, String from, String to) {
JsonNode value = node.remove(from);
if (value != null) {
node.set(to, value);
}
}
/** Copied from the monolith: the shared original serves six other callers and stays there. */
private Map<String, Object> jsonObjectToMap(JsonNode node) {
Map<String, Object> out = new LinkedHashMap<>();
@@ -780,7 +780,7 @@ public class LambdaCfnProvisioner implements CfnResourceProvisioner {
if (variables == null || variables.isNull() || variables.isMissingNode()) {
return Map.of();
}
requireType("Variables", variables, JsonNodeType.OBJECT);
CfnPropertyTypes.requireType("Variables", variables, JsonNodeType.OBJECT);
Map<String, String> vars = new HashMap<>();
variables.fields().forEachRemaining(e -> vars.put(e.getKey(), e.getValue().asText()));
return vars;
@@ -794,32 +794,15 @@ public class LambdaCfnProvisioner implements CfnResourceProvisioner {
/**
* The list-of-strings property {@code source}, or null when the template leaves it out,
* {@code Ref: AWS::NoValue} directly or through {@code Fn::If} included. A literal of another
* type is refused (see {@link #requireType}), and so is an intrinsic that yields a string (see
* {@link CloudFormationTemplateEngine#yieldsString}). Any other intrinsic is read through
* {@link CloudFormationTemplateEngine#resolveStringList}, as CloudFormation reads a {@code Ref}
* to a {@code CommaDelimitedList} parameter, which the engine resolves to the comma-joined text,
* and {@code Fn::Split} (measured, eu-west-1, 2026-10-18).
* {@code Ref: AWS::NoValue} directly or through {@code Fn::If} included; see
* {@link CfnPropertyTypes#readStringList}.
*/
private static List<String> resolveStringList(JsonNode props, String source,
CloudFormationTemplateEngine engine) {
if (props == null || !props.has(source) || props.get(source).isNull()) {
return null;
}
JsonNode raw = props.get(source);
if (raw.isValueNode()) {
requireType(source, raw, JsonNodeType.ARRAY);
}
if (raw.isObject()) {
JsonNode resolved = engine.resolveNodeOmittingNoValue(raw);
if (resolved == null || resolved.isNull() || resolved.isMissingNode()) {
return null;
}
if (resolved.isObject() || (!resolved.isArray() && engine.yieldsString(raw))) {
requireType(source, resolved, JsonNodeType.ARRAY);
}
}
return engine.resolveStringList(raw);
return CfnPropertyTypes.readStringList(source, props.get(source), engine);
}
private List<Object> resolveObjectListOrEmpty(JsonNode props, String source,
@@ -844,7 +827,7 @@ public class LambdaCfnProvisioner implements CfnResourceProvisioner {
/**
* The property {@code source}, or null when the template leaves it out, {@code Ref: AWS::NoValue}
* directly or through {@code Fn::If} included. A value of another type than {@code expected} is
* refused before the function is touched; see {@link #requireType}.
* refused before the function is touched; see {@link CfnPropertyTypes#requireType}.
*/
private static JsonNode resolveTyped(JsonNode props, String source, JsonNodeType expected,
CloudFormationTemplateEngine engine) {
@@ -855,30 +838,10 @@ public class LambdaCfnProvisioner implements CfnResourceProvisioner {
if (resolved == null || resolved.isNull() || resolved.isMissingNode()) {
return null;
}
requireType(source, resolved, expected);
CfnPropertyTypes.requireType(source, resolved, expected);
return resolved;
}
/**
* Refuses a value of another type than {@code expected} 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: "Property [Layers] expected type: JSONArray, found: String".
*/
private static void requireType(String property, JsonNode value, JsonNodeType expected) {
if (value.getNodeType() != expected) {
throw new AwsException("ValidationError", "Property [" + property + "] expected type: "
+ jsonTypeName(expected) + ", found: " + jsonTypeName(value.getNodeType()), 400);
}
}
private static String jsonTypeName(JsonNodeType type) {
return switch (type) {
case OBJECT -> "JSONObject";
case ARRAY -> "JSONArray";
default -> "String";
};
}
private static Map<String, Object> mapWithNullValue(String key) {
Map<String, Object> map = new HashMap<>();
map.put(key, null);