Changes in the S3 Event Notifications API from version 1 to version 2 - Amazon SDK for Java 2.x
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Changes in the S3 Event Notifications API from version 1 to version 2

This topic details the changes in the S3 Event Notifications API from version 1.x (v1) to version 2 .x (v2) of the Amazon SDK for Java.

High-level changes

Structural changes

V1 uses static inner classes for EventNotificationRecord types and their attributes, whereas v2 uses separate public classes for EventNotificationRecord types.

Naming convention changes

In v1, attribute class names include the suffix Entity, whereas v2 omits this suffix for simpler naming: for example, eventData instead of eventDataEntity.

Changes in dependencies, packages and class names

In v1, S3 Event Notification API classes are transitively imported with along with the S3 module (artifactId aws-java-sdk-s3). However, in v2, you need to add a dependency on the s3-event-notifications artifact.

Change v1 v2

Maven dependencies

<dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-bom</artifactId> <version>1.X.X</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-s3</artifactId> </dependency> </dependencies>
<dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.X.X1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>s3-event-notifications</artifactId> </dependency> </dependencies>
Package name com.amazonaws.services.s3.event software.amazon.awssdk.eventnotifications.s3.model
Class names

S3EventNotification

S3EventNotification.S3EventNotificationRecord

S3EventNotification.GlacierEventDataEntity

S3EventNotification.IntelligentTieringEventDataEntity

S3EventNotification.LifecycleEventDataEntity

S3EventNotification.ReplicationEventDataEntity

S3EventNotification.RequestParametersEntity

S3EventNotification.ResponseElementsEntity

S3EventNotification.RestoreEventDataEntity

S3EventNotification.S3BucketEntity

S3EventNotification.S3Entity

S3EventNotification.S3ObjectEntity

S3EventNotification.TransitionEventDataEntity

S3EventNotification.UserIdentityEntity

S3EventNotification

S3EventNotificationRecord

GlacierEventData

IntelligentTieringEventData

LifecycleEventData

ReplicationEventData

RequestParameters

ResponseElements

RestoreEventData

S3Bucket

S3

S3Object

TransitionEventData

UserIdentity

1 Latest version.

API changes

JSON to S3EventNotification and reverse

Use case v1 v2
Create S3EventNotification from JSON String
S3EventNotification notification = S3EventNotification.parseJson(message.body());
S3EventNotification notification = S3EventNotification.fromJson(message.body());
Convert S3EventNotification to JSON String
String json = notification.toJson();
String json = notification.toJson();

Access attributes of S3EventNotification

Use case v1 v2
Retrieve records from a notification
List<S3EventNotification.S3EventNotificationRecord> records = notifcation.getRecords();
List<S3EventNotificationRecord> records = notification.getRecords();
Retrieve a record from a list of records
S3EventNotification.S3EventNotificationRecord record = records.stream().findAny().get();
S3EventNotificationRecord record = records.stream().findAny().get();
Retrieve Glacier event data
S3EventNotification.GlacierEventDataEntity glacierEventData = record.getGlacierEventData();
GlacierEventData glacierEventData = record.getGlacierEventData();
Retrieve restore event data from a Glacier event
S3EventNotification.RestoreEventDataEntity restoreEventData = glacierEventData.getRestoreEventDataEntity();
RestoreEventData restoreEventData = glacierEventData.getRestoreEventData();
Retrieve request parameters
S3EventNotification.RequestParametersEntity requestParameters = record.getRequestParameters();
RequestParameters requestParameters = record.getRequestParameters();
Retrieve Intelligent Tiering event data
S3EventNotification.IntelligentTieringEventDataEntity tieringEventData = record.getIntelligentTieringEventData();
IntelligentTieringEventData intelligentTieringEventData = record.getIntelligentTieringEventData();
Retrieve lifecyle event data
S3EventNotification.LifecycleEventDataEntity lifecycleEventData = record.getLifecycleEventData();
LifecycleEventData lifecycleEventData = record.getLifecycleEventData();
Retrieve event name as enum
S3Event eventNameAsEnum = record.getEventNameAsEnum();
//getEventNameAsEnum does not exist; use 'getEventName()' String eventName = record.getEventName();
Retrieve replication event data
S3EventNotification.ReplicationEventDataEntity replicationEntity = record.getReplicationEventDataEntity();
ReplicationEventData replicationEventData = record.getReplicationEventData();
Retrieve S3 bucket and object information
S3EventNotification.S3Entity s3 = record.getS3();
S3 s3 = record.getS3();
Retrieve user identity information
S3EventNotification.UserIdentityEntity userIdentity = record.getUserIdentity();
UserIdentity userIdentity = record.getUserIdentity();
Retrieve response elements
S3EventNotification.ResponseElementsEntity responseElements = record.getResponseElements();
ResponseElements responseElements = record.getResponseElements();

Migrate S3EventNotification using the aws-lambda-java-events library.

If you use aws-lambda-java-events to work with S3 notification events within a Lambda function, we recommend that you upgrade to the latest 3.x.x version. Recent versions eliminate all dependencies on Amazon SDK for Java 1.x from the S3 event notification API.