How do you configure the endpoint for Amazon S3 by using the AWS SDK V2?

Viewed 2785

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?

1 Answers

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();
Related