Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped the default S3 endpoint to region of the client #9459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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 static final String GLOBAL_S3_ENDPOINT = "s3.amazonaws.com";

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

Expand Down Expand Up @@ -174,7 +174,11 @@ synchronized AmazonAsyncS3WithCredentials buildClient(
final AwsCredentialsProvider credentials = buildCredentials(logger, clientSettings);
builder.credentialsProvider(credentials);

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

String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : s3Endpoint;
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 @@ -98,7 +98,7 @@ 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 static final String GLOBAL_S3_ENDPOINT = "s3.amazonaws.com";

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

Expand Down Expand Up @@ -204,7 +204,11 @@ 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 s3Endpoint = Strings.hasText(clientSettings.region)
? "s3." + Region.of(clientSettings.region).toString() + ".amazonaws.com"
: GLOBAL_S3_ENDPOINT;
Comment on lines +207 to +209
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we retrieve the endpoint from sdk itself , else this will break for CN and other non-classic partitions .


String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : s3Endpoint;
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
Loading