Migrating to the AWS SDK for Java
This article describes the differences between the AWS SDK for Java and previous Java libraries from Amazon Web Services.
Submitted By: Craig@AWS
AWS Products Used: Amazon S3, Amazon RDS, Amazon SQS, Amazon EC2, Amazon SimpleDB
Language(s): Java
Created On: March 21, 2010
About the AWS SDK for Java
The AWS SDK for Java is a single, downloadable package that includes the AWS Java library, code samples, and documentation. Previously, AWS offered a collection of individual Java libraries for many infrastructure services, but not Amazon S3. Now, you can get started in minutes with a single package that includes the AWS Java library, code samples, and documentation. Additionally, Eclipse Java IDE users can get started with the SDK using the AWS Toolkit for Eclipse.
Learn more about the AWS SDK for Java at https://aws.amazon.com/sdkforjava.
What's New in the AWS SDK for Java Library?
There are a number of differences between the previous Java libraries from AWS and the new AWS SDK for Java. In addition to grouping the libraries into a single package along with documentation and code samples, the AWS SDK for Java makes it easier to use multiple AWS products.
Here are some highlights of new features in the AWS SDK for Java library:
- Support for Amazon S3 — We now provide an officially-supported Java API for working with Amazon S3.
- Improved exception handling - The AWS Java SDK uses runtime (or unchecked) exceptions for catching service-level and client-level issues. See AWS SDK for Java Tips and Tricks for more information.
-
Easier access to data returned from operations — No more
objects.Response - Documentation — More detailed and comprehensive JavaDocs.
- Minor improvements to service interfaces — Minor changes include renaming RunningInstance to just Instance, and correcting unpluralized list properties.
We recommend switching to the new AWS SDK for Java, where you'll continue to get new feature updates and bug fixes.
Overview of API Changes
The following section lists the API differences between the previous Java libraries and the new AWS SDK for Java.
Changes for All Services
The changes that affect all services include:
- Methods that return lists are now pluralized.
Was:List
getAttribute()
Now:List
getAttributes()) - Constructors with parameters have changed.
Was:new CreateDomainRequest(domain)
Now:new CreateDomainRequest().withDomainName(domain))
- The old
types which encapsulateResponse
objects have gone away, operations just return theResult
directly now. This changes the type and removes the need to perform theResult isSet
check.Result() - The
.setEndpoint()
method has moved fromClientConfiguration
to the client directly; more broadly this is because the purpose ofClientConfiguration
has changed from storing client-specific settings to a set of configurations that apply across multiple clients. - Dates are represented as
java.util.Date
objects, instead of strings. - Operations whose parameters are all optional have an additional method form that doesn't require a request object.
- Exceptions are now runtime exceptions (see AWS SDK for Java Tips and Tricks for more information on handling exceptions).
- More specific exception subclasses are available to help developers detect specific error conditions (for example:
NumberDomainBytesExceededException
for Amazon SimpleDB). - The client mock implementations have been removed. Instead, developers are encouraged to use more flexible and full featured mock libraries, such as:
- EasyMock - https://easymock.org/
- jMock - https://www.jmock.org/
- Java package names have changed so that the old client classes (for example:
com.amazonaws.ec2
) don't conflict with the new SDK classes (for example:com.amazonaws.services.ec2
). - toJSONFragment and toXMLFragment methods have been removed from Model objects. Developers who need this functionality are encouraged to use a more standard third-party Java serialization library.
-
unset
methods have been removed. If you need to empty out a list member in a request object, just pass in null to the setter or fluent setter. -
ObjectFactory
classes have been removed to simplify using the libraries. - AWS request IDs are available through all Exception objects and through request/response logs.
- Enums are available for common string values passed in service requests (for example: Amazon EC2's
InstanceType
enum lists the available EC2 instance types).
Service-Specific Changes
The additional changes of interest by service are:
Service | Changes |
---|---|
Amazon EC2 |
|
Amazon SimpleDB |
|
Amazon SQS |
|
Amazon Elastic MapReduce |
|
Additional Resources
Some additional resources to help you build your application include: