Ask Your Question
1

How to create an S3 client using AWS SDK for Java 2.X?

asked 2023-05-13 23:32:46 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-13 23:39:02 +0000

devzero gravatar image

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();
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-13 23:32:46 +0000

Seen: 9 times

Last updated: May 13 '23