diff --git a/.changes/next-release/bugfix-AWSSDKforJavav2-8e9db48.json b/.changes/next-release/bugfix-AWSSDKforJavav2-8e9db48.json
new file mode 100644
index 000000000000..3a39e512c543
--- /dev/null
+++ b/.changes/next-release/bugfix-AWSSDKforJavav2-8e9db48.json
@@ -0,0 +1,6 @@
+{
+ "type": "bugfix",
+ "category": "S3 Event Notification",
+ "contributor": "",
+ "description": "add static modifier to fromJson(InputStream) method of S3EventNotification"
+}
diff --git a/pom.xml b/pom.xml
index cc7d8a9c8f52..a0f16c392812 100644
--- a/pom.xml
+++ b/pom.xml
@@ -680,6 +680,8 @@
software.amazon.awssdk.regions.*
software.amazon.awssdk.utils.JavaSystemSetting
+
+ software.amazon.awssdk.eventnotifications.s3.model.S3EventNotification
true
diff --git a/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotification.java b/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotification.java
index d3e94e92c2ca..aaf506e2cb16 100644
--- a/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotification.java
+++ b/services-custom/s3-event-notifications/src/main/java/software/amazon/awssdk/eventnotifications/s3/model/S3EventNotification.java
@@ -73,7 +73,7 @@ public static S3EventNotification fromJson(byte[] json) {
* @param json the notification message in json format
* @return an instance of notification message S3EventNotification
*/
- public S3EventNotification fromJson(InputStream json) {
+ public static S3EventNotification fromJson(InputStream json) {
return S3EventNotificationReader.create().read(json);
}
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 ff369943bc1f..ef9d2c89154a 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
@@ -18,6 +18,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import java.io.ByteArrayInputStream;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
@@ -454,4 +455,128 @@ void malformedJson_throwsException() {
String json = "{\"Records\":[], \"toto\"}";
assertThatThrownBy(() -> S3EventNotification.fromJson(json)).hasCauseInstanceOf(JsonParseException.class);
}
+
+ @Test
+ void fromJsonInputStream_handlesCorrectly() {
+ String eventJson = "{ "
+ + " \"Records\":[ "
+ + " { "
+ + " \"eventVersion\":\"2.1\","
+ + " \"eventSource\":\"aws:s3\","
+ + " \"awsRegion\":\"us-west-2\","
+ + " \"eventTime\":\"1970-01-01T00:00:00.000Z\","
+ + " \"eventName\":\"ObjectCreated:Put\","
+ + " \"userIdentity\":{ "
+ + " \"principalId\":\"AIDAJDPLRKLG7UEXAMPLE\""
+ + " },"
+ + " \"requestParameters\":{ "
+ + " \"sourceIPAddress\":\"127.0.0.1\""
+ + " },"
+ + " \"responseElements\":{ "
+ + " \"x-amz-request-id\":\"C3D13FE58DE4C810\","
+ + " \"x-amz-id-2\":\"FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD\""
+ + " },"
+ + " \"s3\":{ "
+ + " \"s3SchemaVersion\":\"1.0\","
+ + " \"configurationId\":\"testConfigRule\","
+ + " \"bucket\":{ "
+ + " \"name\":\"mybucket\","
+ + " \"ownerIdentity\":{ "
+ + " \"principalId\":\"A3NL1KOZZKExample\""
+ + " },"
+ + " \"arn\":\"arn:aws:s3:::mybucket\""
+ + " },"
+ + " \"object\":{ "
+ + " \"key\":\"HappyFace.jpg\","
+ + " \"size\":1024,"
+ + " \"eTag\":\"d41d8cd98f00b204e9800998ecf8427e\","
+ + " \"versionId\":\"096fKKXTRTtl3on89fVO.nfljtsv6qko\","
+ + " \"sequencer\":\"0055AED6DCD90281E5\""
+ + " }"
+ + " }"
+ + " }"
+ + " ]"
+ + "}";
+
+ S3EventNotification event = S3EventNotification.fromJson(new ByteArrayInputStream(eventJson.getBytes()));
+
+ assertThat(event.getRecords()).hasSize(1);
+
+ // verify constructors
+ S3EventNotification expected = new S3EventNotification(
+ Collections.singletonList(new S3EventNotificationRecord(
+ "us-west-2",
+ "ObjectCreated:Put",
+ "aws:s3",
+ "1970-01-01T00:00:00.000Z",
+ "2.1",
+ new RequestParameters("127.0.0.1"),
+ new ResponseElements(
+ "FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD", "C3D13FE58DE4C810"),
+ new S3(
+ "testConfigRule",
+ new S3Bucket(
+ "mybucket",
+ new UserIdentity("A3NL1KOZZKExample"),
+ "arn:aws:s3:::mybucket"),
+ new S3Object(
+ "HappyFace.jpg",
+ 1024L,
+ "d41d8cd98f00b204e9800998ecf8427e",
+ "096fKKXTRTtl3on89fVO.nfljtsv6qko",
+ "0055AED6DCD90281E5"),
+ "1.0"
+ ),
+ new UserIdentity("AIDAJDPLRKLG7UEXAMPLE")
+ ))
+ );
+ assertThat(event).isEqualTo(expected);
+
+ // verify getters
+ S3EventNotificationRecord rec = event.getRecords().get(0);
+ assertThat(rec).isNotNull();
+ assertThat(rec.getAwsRegion()).isEqualTo("us-west-2");
+ assertThat(rec.getEventName()).isEqualTo("ObjectCreated:Put");
+ assertThat(rec.getEventTime()).isEqualTo(Instant.parse("1970-01-01T00:00:00.000Z"));
+ assertThat(rec.getEventVersion()).isEqualTo("2.1");
+
+ UserIdentity userIdentity = rec.getUserIdentity();
+ assertThat(userIdentity).isNotNull();
+ assertThat(userIdentity.getPrincipalId()).isEqualTo("AIDAJDPLRKLG7UEXAMPLE");
+
+ RequestParameters requestParameters = rec.getRequestParameters();
+ assertThat(requestParameters).isNotNull();
+ assertThat(requestParameters.getSourceIpAddress()).isEqualTo("127.0.0.1");
+
+ ResponseElements responseElements = rec.getResponseElements();
+ assertThat(responseElements).isNotNull();
+ assertThat(responseElements.getXAmzRequestId()).isEqualTo("C3D13FE58DE4C810");
+ assertThat(responseElements.getXAmzId2())
+ .isEqualTo("FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD");
+
+ S3 s3 = rec.getS3();
+ assertThat(s3).isNotNull();
+ assertThat(s3.getS3SchemaVersion()).isEqualTo("1.0");
+ assertThat(s3.getConfigurationId()).isEqualTo("testConfigRule");
+ S3Bucket s3Bucket = s3.getBucket();
+ assertThat(s3Bucket).isNotNull();
+ assertThat(s3Bucket.getName()).isEqualTo("mybucket");
+ assertThat(s3Bucket.getArn()).isEqualTo("arn:aws:s3:::mybucket");
+ UserIdentity ownerIdentity = s3Bucket.getOwnerIdentity();
+ assertThat(ownerIdentity).isNotNull();
+ assertThat(ownerIdentity.getPrincipalId()).isEqualTo("A3NL1KOZZKExample");
+ S3Object s3Object = s3.getObject();
+ assertThat(s3Object).isNotNull();
+ assertThat(s3Object.getKey()).isEqualTo("HappyFace.jpg");
+ assertThat(s3Object.getETag()).isEqualTo("d41d8cd98f00b204e9800998ecf8427e");
+ assertThat(s3Object.getSizeAsLong()).isEqualTo(1024L);
+ assertThat(s3Object.getVersionId()).isEqualTo("096fKKXTRTtl3on89fVO.nfljtsv6qko");
+ assertThat(s3Object.getSequencer()).isEqualTo("0055AED6DCD90281E5");
+
+ assertThat(rec.getGlacierEventData()).isNull();
+ assertThat(rec.getIntelligentTieringEventData()).isNull();
+ assertThat(rec.getLifecycleEventData()).isNull();
+ assertThat(rec.getReplicationEventData()).isNull();
+
+ }
}