From 0ac9745b66d400746871755a9b06ce016d7aca8b Mon Sep 17 00:00:00 2001 From: Raghuvansh Raj Date: Fri, 18 Aug 2023 16:49:39 +0530 Subject: [PATCH] Scoped the default S3 endpoint to region of the client Signed-off-by: Raghuvansh Raj --- .../java/org/opensearch/repositories/s3/S3AsyncService.java | 6 +++--- .../main/java/org/opensearch/repositories/s3/S3Service.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3AsyncService.java b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3AsyncService.java index 08215ebdd45e0..a80d073f5dde9 100644 --- a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3AsyncService.java +++ b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3AsyncService.java @@ -60,8 +60,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 clientsCache = emptyMap(); /** @@ -174,7 +172,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; diff --git a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Service.java b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Service.java index b13672b4179f8..5c672442db9e0 100644 --- a/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Service.java +++ b/plugins/repository-s3/src/main/java/org/opensearch/repositories/s3/S3Service.java @@ -98,8 +98,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 clientsCache = emptyMap(); /** @@ -204,7 +202,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