2

In AWS SDK V1, I set up my credentials as:

BasicAWSCredentials awsCredentials = new BasicAWSCredentials(Credentials.access_key, Credentials.secret_access_key);

And then set the endpoint as:

EndpointConfiguration endpoint = new EndpointConfiguration("<endpoint URL>", "<region>"); 

And then created the client as:

AmazonS3 s3client = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
            .withEndpointConfiguration(endpoint)
            .build(); 

How do I set up this same client using AWS SDK V2?

smac2020
  • 9,637
  • 4
  • 24
  • 38
aravind
  • 53
  • 1
  • 1
  • 5

2 Answers2

3

Looking at the Javadocs here:

https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/client/builder/SdkClientBuilder.html#endpointOverride-java.net.URI-

See:

endpointOverride

endpointOverride(URI endpointOverride)

Configure the endpoint with which the SDK should communicate.**

Looks like you can create a URI object and pass that when you create the Service client

URI myURI = new URI("<endpoint URL>");

  Region region = Region.US_EAST_1;
  S3Client s3 = S3Client.builder()
                .region(region)
                .endpointOverride(myURI)
                .build();
smac2020
  • 9,637
  • 4
  • 24
  • 38
-1

If u want to use Cloudflare R2 with 1.12.x u need to specify the endpoint as "auto" lowercase:

  AmazonS3 client = AmazonS3ClientBuilder.standard()
                    .withCredentials(
                            new AWSStaticCredentialsProvider(
                                    new BasicAWSCredentials(
                                            ACCESS_KEY_ID, SECRET_ACCESS_KEY)))
                    .withEndpointConfiguration(
                            new AwsClientBuilder.EndpointConfiguration("https://<accountid>.r2.cloudflarestorage.com, "auto"))
                    .build();
metadevj
  • 21
  • 2
  • 2