Best Practices for AWS Development with the AWS SDK for Java - AWS SDK for Java

At Amazon Web Services (AWS), we’re focused on finding ways to improve our products and provide a better customer experience. To do that, we need your feedback. Please take 5 minutes of your time to share insights regarding your experience with Java Spring and your need for Spring integration with AWS.

Click here to take a quick survey

This survey is hosted by an external company (Qualtrics), so the link above does not lead to our website. Please note that AWS will own the data gathered via this survey, and will not share the information/results collected with survey respondents. AWS handles your information as described in the AWS Privacy Notice.

Best Practices for AWS Development with the AWS SDK for Java

The following best practices can help you avoid issues or trouble as you develop AWS applications with the AWS SDK for Java. We’ve organized best practices by service.

Amazon S3

Avoid ResetExceptions

When you upload objects to Amazon S3 by using streams (either through an AmazonS3 client or TransferManager), you might encounter network connectivity or timeout issues. By default, the AWS SDK for Java attempts to retry failed transfers by marking the input stream before the start of a transfer and then resetting it before retrying.

If the stream doesn’t support mark and reset, the SDK throws a ResetException when there are transient failures and retries are enabled.

Best Practice

We recommend that you use streams that support mark and reset operations.

The most reliable way to avoid a ResetException is to provide data by using a File or FileInputStream, which the AWS SDK for Java can handle without being constrained by mark and reset limits.

If the stream isn’t a FileInputStream but does support mark and reset, you can set the mark limit by using the setReadLimit method of RequestClientOptions. Its default value is 128 KB. Setting the read limit value to one byte greater than the size of stream will reliably avoid a ResetException.

For example, if the maximum expected size of a stream is 100,000 bytes, set the read limit to 100,001 (100,000 + 1) bytes. The mark and reset will always work for 100,000 bytes or less. Be aware that this might cause some streams to buffer that number of bytes into memory.