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 653034ee9afde..4756cca7cba47 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 @@ -59,7 +59,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 REGION_SPECIFIC_S3_ENDPOINT_FORMAT = "s3.%s.amazonaws.com"; private volatile Map clientsCache = emptyMap(); @@ -173,7 +173,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 = String.format(REGION_SPECIFIC_S3_ENDPOINT_FORMAT, Region.of(clientSettings.region).toString()); + + 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 c13e5b76b9269..3305a46548533 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 @@ -96,7 +96,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 REGION_SPECIFIC_S3_ENDPOINT_FORMAT = "s3.%s.amazonaws.com"; private volatile Map clientsCache = emptyMap(); @@ -202,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 = String.format(REGION_SPECIFIC_S3_ENDPOINT_FORMAT, Region.of(clientSettings.region).toString()); + + 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