feat(eventbridge): add UpdateEventBus action (#834)

* feat(eventbridge): add UpdateEventBus action

* address Copilot review feedback on UpdateEventBus
This commit is contained in:
Marvelous Ikponmwosa authored and GitHub committed 2026-05-14 20:31:35 -05:00
1 parent 6acbf1f2c2
commit b25fcc28a2
5 files changed
+374

No files matched your search

@@ -53,6 +53,7 @@ public class EventBridgeHandler {
case "CreateEventBus" -> handleCreateEventBus(request, region);
case "DeleteEventBus" -> handleDeleteEventBus(request, region);
case "DescribeEventBus" -> handleDescribeEventBus(request, region);
case "UpdateEventBus" -> handleUpdateEventBus(request, region);
case "ListEventBuses" -> handleListEventBuses(request, region);
case "PutRule" -> handlePutRule(request, region);
case "DeleteRule" -> handleDeleteRule(request, region);
@@ -117,6 +118,21 @@ public class EventBridgeHandler {
return Response.ok(buildBusNode(bus)).build();
}
private Response handleUpdateEventBus(JsonNode request, String region) {
String name = request.path("Name").asText(null);
String description = request.path("Description").asText(null);
String kmsKey = request.path("KmsKeyIdentifier").asText(null);
// Empty {} is treated as "no change", matching how omitted/null inputs flow.
// Only a populated object triggers a write to the bus's nested config field.
JsonNode dlqNode = request.path("DeadLetterConfig");
String dlq = (dlqNode.isObject() && !dlqNode.isEmpty()) ? dlqNode.toString() : null;
JsonNode logNode = request.path("LogConfig");
String logCfg = (logNode.isObject() && !logNode.isEmpty()) ? logNode.toString() : null;
EventBus bus = eventBridgeService.updateEventBus(
name, description, kmsKey, dlq, logCfg, region);
return Response.ok(buildBusNode(bus)).build();
}
private Response handleListEventBuses(JsonNode request, String region) {
String namePrefix = request.path("NamePrefix").asText(null);
List<EventBus> buses = eventBridgeService.listEventBuses(namePrefix, region);
@@ -506,6 +522,29 @@ public class EventBridgeHandler {
if (bus.getPolicy() != null) {
node.put("Policy", bus.getPolicy());
}
if (bus.getKmsKeyIdentifier() != null) {
node.put("KmsKeyIdentifier", bus.getKmsKeyIdentifier());
}
// Stored as raw JSON strings; emitted as JSON objects so SDK clients
// can deserialize them as structs. Do NOT use node.put(...) here.
if (bus.getDeadLetterConfig() != null) {
try {
node.set("DeadLetterConfig", objectMapper.readTree(bus.getDeadLetterConfig()));
} catch (Exception e) {
LOG.warnv("Failed to parse stored DeadLetterConfig for bus {0} (arn={1}); "
+ "field omitted from response. Stored value: {2}. Error: {3}",
bus.getName(), bus.getArn(), bus.getDeadLetterConfig(), e.getMessage());
}
}
if (bus.getLogConfig() != null) {
try {
node.set("LogConfig", objectMapper.readTree(bus.getLogConfig()));
} catch (Exception e) {
LOG.warnv("Failed to parse stored LogConfig for bus {0} (arn={1}); "
+ "field omitted from response. Stored value: {2}. Error: {3}",
bus.getName(), bus.getArn(), bus.getLogConfig(), e.getMessage());
}
}
return node;
}
@@ -177,6 +177,52 @@ public class EventBridgeService {
"EventBus not found: " + effectiveName, 404));
}
public EventBus updateEventBus(String name,
String description,
String kmsKeyIdentifier,
String deadLetterConfig,
String logConfig,
String region) {
// Name identifies the bus; never mutated (AWS does not support rename).
String effectiveName = name == null || name.isBlank() ? "default" : name;
EventBus bus = "default".equals(effectiveName)
? getOrCreateDefaultBus(region)
: busStore.get(busKey(region, effectiveName))
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"EventBus not found: " + effectiveName, 404));
// Only mark dirty when a field is both non-blank AND different from
// the value currently on the bus — re-sending the same value is a no-op.
boolean dirty = false;
if (description != null && !description.isBlank()
&& !description.equals(bus.getDescription())) {
bus.setDescription(description);
dirty = true;
}
if (kmsKeyIdentifier != null && !kmsKeyIdentifier.isBlank()
&& !kmsKeyIdentifier.equals(bus.getKmsKeyIdentifier())) {
bus.setKmsKeyIdentifier(kmsKeyIdentifier);
dirty = true;
}
if (deadLetterConfig != null && !deadLetterConfig.isBlank()
&& !deadLetterConfig.equals(bus.getDeadLetterConfig())) {
bus.setDeadLetterConfig(deadLetterConfig);
dirty = true;
}
if (logConfig != null && !logConfig.isBlank()
&& !logConfig.equals(bus.getLogConfig())) {
bus.setLogConfig(logConfig);
dirty = true;
}
if (dirty) {
busStore.put(busKey(region, effectiveName), bus);
LOG.infov("Updated event bus: {0} (arn={1}) in region {2}",
effectiveName, bus.getArn(), region);
}
return bus;
}
public List<EventBus> listEventBuses(String namePrefix, String region) {
getOrCreateDefaultBus(region);
String storagePrefix = "bus:" + region + ":";
@@ -15,6 +15,9 @@ public class EventBus {
private Map<String, String> tags = new HashMap<>();
private Instant createdTime;
private String policy;
private String kmsKeyIdentifier;
private String deadLetterConfig; // raw JSON: {"Arn":"..."}
private String logConfig; // raw JSON: {"IncludeDetail":"...","Level":"..."}
public EventBus() {}
@@ -42,4 +45,13 @@ public class EventBus {
public String getPolicy() { return policy; }
public void setPolicy(String policy) { this.policy = policy; }
public String getKmsKeyIdentifier() { return kmsKeyIdentifier; }
public void setKmsKeyIdentifier(String kmsKeyIdentifier) { this.kmsKeyIdentifier = kmsKeyIdentifier; }
public String getDeadLetterConfig() { return deadLetterConfig; }
public void setDeadLetterConfig(String deadLetterConfig) { this.deadLetterConfig = deadLetterConfig; }
public String getLogConfig() { return logConfig; }
public void setLogConfig(String logConfig) { this.logConfig = logConfig; }
}