Skip to content

Commit

Permalink
SNOW-1446336: Use S3 regional url domain base on region name (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored May 27, 2024
1 parent fb23408 commit 3c4b521
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ private void setupSnowflakeS3Client(
} else {
if (region != null) {
if (this.isUseS3RegionalUrl) {
String domainSuffixForRegionalUrl = getDomainSuffixForRegionalUrl(region.getName());
amazonS3Builder.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
"s3." + region.getName() + ".amazonaws.com", region.getName()));
"s3." + region.getName() + "." + domainSuffixForRegionalUrl, region.getName()));
} else {
amazonS3Builder.withRegion(region.getName());
}
Expand All @@ -230,6 +231,10 @@ private void setupSnowflakeS3Client(
amazonClient = (AmazonS3) amazonS3Builder.build();
}

static String getDomainSuffixForRegionalUrl(String regionName) {
return regionName.startsWith("cn-") ? "amazonaws.com.cn" : "amazonaws.com";
}

// Returns the Max number of retry attempts
@Override
public int getMaxRetries() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Snowflake Computing Inc. All rights reserved.
*/
package net.snowflake.client.jdbc.cloud.storage;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class SnowflakeS3ClientTest {

@Test
public void shouldDetermineDomainForRegion() {
assertEquals("amazonaws.com", SnowflakeS3Client.getDomainSuffixForRegionalUrl("us-east-1"));
assertEquals(
"amazonaws.com.cn", SnowflakeS3Client.getDomainSuffixForRegionalUrl("cn-northwest-1"));
}
}

0 comments on commit 3c4b521

Please sign in to comment.