Reputation: 83
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?
Upvotes: 5
Views: 23800
Reputation: 47
To use Cloudflare R2 storage with software.amazon.awssdk.s3 2.20.x the region needs to be set to "auto" and endpointOverride needs to be set:
AwsBasicCredentials awsBasicCredentials =
AwsBasicCredentials.create(ACCESS_KEY_ID, SECRET_ACCESS_KEY);
S3Client s3Client = S3Client.builder()
.credentialsProvider(
StaticCredentialsProvider.create(awsBasicCredentials))
.region(Region.of("auto"))
.endpointOverride(URI.create("https://<accountid>.r2.cloudflarestorage.com"))
.build();
For legacy applications, 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();
Upvotes: -2
Reputation: 10734
Looking at the Javadocs here:
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();
Upvotes: 9