The Amazon SDK for Java 1.x has entered maintenance mode as of July 31, 2024,
and will reach end-of-support
Best Practices for Amazon Development with the Amazon SDK for Java
The following best practices can help you avoid issues or trouble as you develop Amazon applications with the Amazon SDK for Java. We’ve organized best practices by service.
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
Amazon 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
If the stream isn’t a
FileInputStreamsetReadLimit
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.