fix(eventbridge): preserve target role ARN configuration (#4946)

* fix(eventbridge): preserve target role ARN configuration

* fix(eventbridge): handle stored targets without an ARN

---------

Co-authored-by: Vamsi Akavarapu <16164447+vamsiak@users.noreply.github.com>
This commit is contained in:
vamsiakandVamsi Akavarapu authored and GitHub committed 2026-10-03 09:42:03 -04:00
1 parent ab2c0def0a
commit a18aa246d3
8 files changed
+392 -3

No files matched your search

@@ -224,6 +224,7 @@ public class EventBridgeHandler {
input.isEmpty() ? null : input,
inputPath.isEmpty() ? null : inputPath
);
target.setRoleArn(t.path("RoleArn").asText(null));
target.setInputTransformer(InputTransformer.fromJson(t.path("InputTransformer")));
JsonNode sqsParamsNode = t.path("SqsParameters");
if (!sqsParamsNode.isMissingNode() && sqsParamsNode.isObject()) {
@@ -317,6 +318,9 @@ public class EventBridgeHandler {
if (t.getRetryPolicy() != null) {
node.set("RetryPolicy", objectMapper.valueToTree(t.getRetryPolicy()));
}
if (t.getRoleArn() != null) {
node.put("RoleArn", t.getRoleArn());
}
if (t.getDeadLetterConfig() != null) {
node.set("DeadLetterConfig", objectMapper.valueToTree(t.getDeadLetterConfig()));
}
@@ -406,14 +406,20 @@ public class EventBridgeService implements ResourceProvider {
// ──────────────────────────── Targets ────────────────────────────
public int putTargets(String ruleName, String busName, List<Target> newTargets, String region) {
validateRetrySettings(newTargets);
validateTargetSettings(newTargets);
String effectiveBus = resolvedBusName(busName);
String key = ruleKey(region, effectiveBus, ruleName);
ruleStore.get(key)
Rule rule = ruleStore.get(key)
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"Rule not found: " + ruleName, 400));
List<Target> existing = new ArrayList<>(targetStore.get(key).orElse(new ArrayList<>()));
for (Target newTarget : newTargets) {
if (newTarget.getRoleArn() == null && isCrossAccountEventBus(newTarget.getArn(), rule)) {
existing.stream()
.filter(t -> t.getId().equals(newTarget.getId()) && newTarget.getArn().equals(t.getArn()))
.findFirst()
.ifPresent(t -> newTarget.setRoleArn(t.getRoleArn()));
}
existing.removeIf(t -> t.getId().equals(newTarget.getId()));
existing.add(newTarget);
}
@@ -422,7 +428,16 @@ public class EventBridgeService implements ResourceProvider {
return 0;
}
private static void validateRetrySettings(List<Target> targets) {
private boolean isCrossAccountEventBus(String targetArn, Rule rule) {
if (!AwsArnUtils.isArnFor(targetArn, "events")) {
return false;
}
AwsArnUtils.Arn arn = AwsArnUtils.parse(targetArn);
String accountId = rule.getAccountId() != null ? rule.getAccountId() : regionResolver.getAccountId();
return arn.resource().startsWith("event-bus/") && AwsArnUtils.isForeignAccount(arn, accountId);
}
private static void validateTargetSettings(List<Target> targets) {
for (int i = 0; i < targets.size(); i++) {
Target target = targets.get(i);
Integer attempts = target.getRetryPolicy() != null ? target.getRetryPolicy().maximumRetryAttempts() : null;
@@ -443,6 +458,12 @@ public class EventBridgeService implements ResourceProvider {
field = "deadLetterConfig.arn";
value = arn;
constraint = arn.isEmpty() ? "length greater than or equal to 1" : "length less than or equal to 1600";
} else if (target.getRoleArn() != null
&& (target.getRoleArn().isEmpty() || target.getRoleArn().length() > 1600)) {
field = "roleArn";
value = target.getRoleArn();
constraint = target.getRoleArn().isEmpty()
? "length greater than or equal to 1" : "length less than or equal to 1600";
}
if (field != null) {
throw new AwsException("ValidationException", "1 validation error detected: Value '" + value
@@ -11,6 +11,7 @@ public class Target {
private String id;
private String arn;
private String roleArn;
private String input;
private String inputPath;
private InputTransformer inputTransformer;
@@ -35,6 +36,9 @@ public class Target {
public String getArn() { return arn; }
public void setArn(String arn) { this.arn = arn; }
public String getRoleArn() { return roleArn; }
public void setRoleArn(String roleArn) { this.roleArn = roleArn; }
public String getInput() { return input; }
public void setInput(String input) { this.input = input; }