Skip to content

Commit 6a96cbc

Browse files
committed
Scoped the default S3 endpoint to region of the client
Signed-off-by: Raghuvansh Raj <raghraaj@amazon.com>
1 parent 48d4087 commit 6a96cbc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3AsyncService.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class S3AsyncService implements Closeable {
6060

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

63-
private static final String DEFAULT_S3_ENDPOINT = "s3.amazonaws.com";
63+
private static final String GLOBAL_S3_ENDPOINT = "s3.amazonaws.com";
6464

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

@@ -174,7 +174,11 @@ synchronized AmazonAsyncS3WithCredentials buildClient(
174174
final AwsCredentialsProvider credentials = buildCredentials(logger, clientSettings);
175175
builder.credentialsProvider(credentials);
176176

177-
String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : DEFAULT_S3_ENDPOINT;
177+
String s3Endpoint = Strings.hasText(clientSettings.region)
178+
? "s3." + Region.of(clientSettings.region).toString() + ".amazonaws.com"
179+
: GLOBAL_S3_ENDPOINT;
180+
181+
String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : s3Endpoint;
178182
if ((endpoint.startsWith("http://") || endpoint.startsWith("https://")) == false) {
179183
// Manually add the schema to the endpoint to work around https://github.com/aws/aws-sdk-java/issues/2274
180184
endpoint = clientSettings.protocol.toString() + "://" + endpoint;

plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Service.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class S3Service implements Closeable {
9898

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

101-
private static final String DEFAULT_S3_ENDPOINT = "s3.amazonaws.com";
101+
private static final String GLOBAL_S3_ENDPOINT = "s3.amazonaws.com";
102102

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

@@ -204,7 +204,11 @@ AmazonS3WithCredentials buildClient(final S3ClientSettings clientSettings) {
204204
builder.httpClientBuilder(buildHttpClient(clientSettings));
205205
builder.overrideConfiguration(buildOverrideConfiguration(clientSettings));
206206

207-
String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : DEFAULT_S3_ENDPOINT;
207+
String s3Endpoint = Strings.hasText(clientSettings.region)
208+
? "s3." + Region.of(clientSettings.region).toString() + ".amazonaws.com"
209+
: GLOBAL_S3_ENDPOINT;
210+
211+
String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : s3Endpoint;
208212
if ((endpoint.startsWith("http://") || endpoint.startsWith("https://")) == false) {
209213
// Manually add the schema to the endpoint to work around https://github.com/aws/aws-sdk-java/issues/2274
210214
// TODO: Remove this once fixed in the AWS SDK

0 commit comments

Comments
 (0)