Skip to content

Commit

Permalink
Scoped the default S3 endpoint to region of the client
Browse files Browse the repository at this point in the history
Signed-off-by: Raghuvansh Raj <raghraaj@amazon.com>
  • Loading branch information
raghuvanshraj committed Aug 21, 2023
1 parent 2f4545a commit bb7481b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class S3AsyncService implements Closeable {

private static final String STS_ENDPOINT_OVERRIDE_SYSTEM_PROPERTY = "aws.stsEndpointOverride";

private static final String DEFAULT_S3_ENDPOINT = "s3.amazonaws.com";

private volatile Map<S3ClientSettings, AmazonAsyncS3Reference> clientsCache = emptyMap();

/**
Expand Down Expand Up @@ -173,7 +171,9 @@ synchronized AmazonAsyncS3WithCredentials buildClient(
final AwsCredentialsProvider credentials = buildCredentials(logger, clientSettings);
builder.credentialsProvider(credentials);

String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : DEFAULT_S3_ENDPOINT;
String regionSpecificS3Endpoint = "s3." + Region.of(clientSettings.region).toString() + ".amazonaws.com";

String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : regionSpecificS3Endpoint;
if ((endpoint.startsWith("http://") || endpoint.startsWith("https://")) == false) {
// Manually add the schema to the endpoint to work around https://github.com/aws/aws-sdk-java/issues/2274
endpoint = clientSettings.protocol.toString() + "://" + endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ class S3Service implements Closeable {

private static final String STS_ENDPOINT_OVERRIDE_SYSTEM_PROPERTY = "aws.stsEndpointOverride";

private static final String DEFAULT_S3_ENDPOINT = "s3.amazonaws.com";

private volatile Map<S3ClientSettings, AmazonS3Reference> clientsCache = emptyMap();

/**
Expand Down Expand Up @@ -202,7 +200,9 @@ AmazonS3WithCredentials buildClient(final S3ClientSettings clientSettings) {
builder.httpClientBuilder(buildHttpClient(clientSettings));
builder.overrideConfiguration(buildOverrideConfiguration(clientSettings));

String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : DEFAULT_S3_ENDPOINT;
String regionSpecificS3Endpoint = "s3." + Region.of(clientSettings.region).toString() + ".amazonaws.com";

String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : regionSpecificS3Endpoint;
if ((endpoint.startsWith("http://") || endpoint.startsWith("https://")) == false) {
// Manually add the schema to the endpoint to work around https://github.com/aws/aws-sdk-java/issues/2274
// TODO: Remove this once fixed in the AWS SDK
Expand Down

0 comments on commit bb7481b

Please sign in to comment.