Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create an S3 client using AWS SDK for Java 2.X, you can follow the below steps:

  1. Add the AWS SDK for Java 2.X dependency to your project using a build tool like Maven or Gradle.

Maven:

<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>s3</artifactId>
    <version>2.16.73</version>
</dependency>

Gradle:

implementation 'software.amazon.awssdk:s3:2.16.73'
  1. Create an instance of the S3Client class using the static builder() method:
S3Client s3Client = S3Client.builder()
    .region(Region.US_EAST_1)
    .build();
  1. Use the S3Client instance to interact with S3. For example, you can list S3 buckets using the listBuckets() method:
ListBucketsResponse listBucketsResponse = s3Client.listBuckets();
listBucketsResponse.buckets().forEach(bucket -> System.out.println(bucket.name()));
  1. When you're finished using the S3 client, close the client to release any open resources using the close() method:
s3Client.close();