Skip to content

Fix S3 event parsing when eventName is present but eventTime is not #6095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS S3 Event Notifications",
"contributor": "reifiedbeans",
"description": "Fixed parsing of S3 event notifications to allow eventTime to be null when eventName is not"
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private S3EventNotificationRecord readEventNotificationRecord(JsonNode jsonNode)
eventNotificationRecord.setEventSource(eventSource);

String eventTime = expectStringOrNull(recordNode, "eventTime");
eventNotificationRecord.setEventTime(eventName != null ? Instant.parse(eventTime) : null);
eventNotificationRecord.setEventTime(eventTime != null ? Instant.parse(eventTime) : null);

RequestParameters requestParameters = readRequestParameters(recordNode.get("requestParameters"));
eventNotificationRecord.setRequestParameters(requestParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,53 @@ void missingField_shouldBeNull() {
assertThat(rec.getResponseElements()).isNull();
}

@Test
void eventTimeIsNullWhenEventNamePresent_shouldSucceed() {
String json = "{\n"
+ " \"Records\" : [ {\n"
+ " \"eventVersion\" : \"2.1\",\n"
+ " \"eventSource\" : \"aws:s3\",\n"
+ " \"awsRegion\" : \"us-west-2\",\n"
// missing eventTime
+ " \"eventName\" : \"ObjectCreated:Put\",\n"
+ " \"userIdentity\" : {\n"
+ " \"principalId\" : \"AIDAJDPLRKLG7UEXAMUID\"\n"
+ " },\n"
+ " \"requestParameters\" : {\n"
+ " \"sourceIPAddress\" : \"127.1.2.3\"\n"
+ " },\n"
+ " \"responseElements\":{\n"
+ " \"x-amz-request-id\":\"C3D13FE58DE4C810\",\n"
+ " \"x-amz-id-2\":\"FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD\"\n"
+ " },\n"
+ " \"s3\" : {\n"
+ " \"s3SchemaVersion\" : \"1.0\",\n"
+ " \"configurationId\" : \"testConfigRule\",\n"
+ " \"bucket\" : {\n"
+ " \"name\" : \"mybucket-test\",\n"
+ " \"ownerIdentity\" : {\n"
+ " \"principalId\" : \"A3NL1KOZZKExample\"\n"
+ " },\n"
+ " \"arn\" : \"arn:aws:s3:::mybucket\"\n"
+ " },\n"
+ " \"object\" : {\n"
+ " \"key\" : \"HappyFace-test.jpg\",\n"
+ " \"size\" : 2048,\n"
+ " \"eTag\" : \"d41d8cd98f00b204e9800998ecf8etag\",\n"
+ " \"versionId\" : \"096fKKXTRTtl3on89fVO.nfljtsv6vid\",\n"
+ " \"sequencer\" : \"0055AED6DCD9028SEQ\"\n"
+ " }\n"
+ " }\n"
+ " } ]\n"
+ "}";

S3EventNotification event = S3EventNotification.fromJson(json);
S3EventNotificationRecord rec = event.getRecords().get(0);
assertThat(rec).isNotNull();
assertThat(rec.getEventName()).isEqualTo("ObjectCreated:Put");
assertThat(rec.getEventTime()).isNull();
}

@Test
void extraFields_areIgnored() {
String json = "{\"Records\":[], \"toto\":123}";
Expand Down
Loading