fix(eventbridge): answer PutEvents to a missing event bus as AWS does (#6748)

A PutEvents entry naming an event bus that does not exist failed with
InvalidArgument "EventBus not found" and counted in FailedEntryCount.
The EventBridge User Guide, on handling PutEvents failures: "If you use
PutEvents to publish an event to an event bus that does not exist,
EventBridge event matching will not find a corresponding rule and will
drop the event. Although EventBridge will send a 200 response, it will
not fail the request or include the event in the FailedEntryCount value
of the request response." botocore models no not-found error for
PutEvents, only InternalException, and the API Reference lists none.

Such an entry is now answered as published, with an event id and not
counted as failed, and dropped: it reaches no rule and no archive.
Floci logs the drop at INFO. An entry that is not valid, missing a
required field or with a Detail that is no JSON object, still fails as
before, whichever bus it names.

Only the PutEvents action changes. Floci's own deliveries to a bus, for
a rule's event bus target, a pipe, a schedule, a Lambda destination or
a replay, still fail an entry for a bus that does not exist: the
guide's sentence is about the action, and no document says how AWS
answers those deliveries.

Step Functions' optimized events:putEvents integration calls the
action, so a task publishing to a missing bus no longer fails with
EventBridge.FailedEntry; step-functions.md listed that as a deviation,
which is gone. Its two tests that used a missing bus to have an entry
rejected now leave out the entry's Source instead, and a third checks
that a task publishing to a missing bus succeeds.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-27 17:34:34 -05:00
1 parent b6d9e4c7a4
commit 32cbf73adc
8 files changed
+133 -8

No files matched your search

@@ -393,7 +393,7 @@ public class EventBridgeHandler {
entries.add(entry);
}
}
EventBridgeService.PutEventsResult result = eventBridgeService.putEvents(entries, region);
EventBridgeService.PutEventsResult result = eventBridgeService.putEventsFromRequest(entries, region);
ObjectNode response = objectMapper.createObjectNode();
response.put("FailedEntryCount", result.failedCount());
ArrayNode resultEntries = response.putArray("Entries");
@@ -916,6 +916,25 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
* {@code null} whenever the target is in the caller's own account.
*/
public PutEventsResult putEvents(List<Map<String, Object>> entries, String region, String accountId) {
return putEvents(entries, region, accountId, false);
}
/**
* Publishes the entries of a {@code PutEvents} request. As {@link #putEvents(List, String)}, except that
* an entry for an event bus that does not exist is answered as published, with an event id and not
* counted as failed, and goes no further, as the EventBridge User Guide gives it: "If you use PutEvents
* to publish an event to an event bus that does not exist, EventBridge event matching will not find a
* corresponding rule and will drop the event. Although EventBridge will send a 200 response, it will not
* fail the request or include the event in the FailedEntryCount value of the request response." Floci's
* own deliveries to a bus, for a rule, a pipe or a schedule, go through {@link #putEvents} and still fail
* such an entry: the guide's sentence is about the action, and no document says how AWS answers them.
*/
public PutEventsResult putEventsFromRequest(List<Map<String, Object>> entries, String region) {
return putEvents(entries, region, null, true);
}
private PutEventsResult putEvents(List<Map<String, Object>> entries, String region, String accountId,
boolean dropForMissingBus) {
int failed = 0;
List<Map<String, String>> resultEntries = new ArrayList<>();
@@ -969,6 +988,12 @@ public class EventBridgeService implements ResourceProvider, StoredResourceArns
if ("default".equals(effectiveBus)) {
getOrCreateDefaultBus(region);
} else if (accountGet(busStore, accountId, busStoreKey).isEmpty()) {
if (dropForMissingBus) {
LOG.infov("PutEvents dropped an event for event bus {0}, which does not exist in {1}",
effectiveBus, region);
resultEntries.add(Map.of("EventId", UUID.randomUUID().toString()));
continue;
}
failed++;
Map<String, String> errorEntry = new HashMap<>();
errorEntry.put("ErrorCode", "InvalidArgument");