Work with Amazon S3
This section provides background information for working with Amazon S3 by using the Amazon SDK for Java 2.x. This section compliments the Amazon S3 Java v2 examples presented in the Code examples section of this guide.
S3 clients in the Amazon SDK for Java 2.x
The Amazon SDK for Java 2.x provides different types of S3 clients. The following table shows the differences and can help you decide what is best for your use cases.
S3 Client | Short description | When to use | Limitation/drawback |
---|---|---|---|
Amazon CRT-based S3 client Interface: S3AsyncClient Builder: S3CrtAsyncClientBuilder |
|
|
|
Java-based S3 async client with multipart enabled Interface: S3AsyncClient Builder: S3AsyncClientBuilder |
See Configure the Java-based S3 async client to use parallel transfers. |
|
Less performant than the Amazon CRT-based S3 client. |
Java-based S3 async client without multipart enabled Interface: S3AsyncClient Builder: S3AsyncClientBuilder |
|
|
No performance optimization. |
Java-based S3 sync client Interface: S3Client Builder: S3ClientBuilder |
|
|
No performance optimization. |
Note
From version 2.18.x and onward, the Amazon SDK for Java 2.x uses virtual hosted-style addressing when including an endpoint override. This applies as long as the bucket name is a valid DNS label.
Call the forcePathStyle
true
in your client
builder to force the client to use path-style addressing for buckets.
The following example shows a service client configured with an endpoint override and using path-style addressing.
S3Client client = S3Client.builder() .region(Region.US_WEST_2) .endpointOverride(URI.create("https://s3.us-west-2.amazonaws.com")) .forcePathStyle(true) .build();