diff --git a/.changes/next-release/bugfix-AWSS3EventNotifications-3774889.json b/.changes/next-release/bugfix-AWSS3EventNotifications-3774889.json new file mode 100644 index 000000000000..6b2f9f8d0e33 --- /dev/null +++ b/.changes/next-release/bugfix-AWSS3EventNotifications-3774889.json @@ -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" +} diff --git a/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/internal/DefaultS3EventNotificationReader.java b/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/internal/DefaultS3EventNotificationReader.java index cdb1f1975e71..47e139869ec7 100644 --- a/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/internal/DefaultS3EventNotificationReader.java +++ b/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/internal/DefaultS3EventNotificationReader.java @@ -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); diff --git a/services-custom/s3-event-notifications/src/test/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotificationReaderTest.java b/services-custom/s3-event-notifications/src/test/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotificationReaderTest.java index ef9d2c89154a..b55a2bb74142 100644 --- a/services-custom/s3-event-notifications/src/test/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotificationReaderTest.java +++ b/services-custom/s3-event-notifications/src/test/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotificationReaderTest.java @@ -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}";