Skip to content

Commit 131d2f4

Browse files
authored
fix(aws-android-sdk-core): modify region parsing for endpoints in vpc (#3024)
1 parent a21e3be commit 131d2f4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

aws-android-sdk-core/src/main/java/com/amazonaws/util/AwsHostNameUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class AwsHostNameUtils {
3232

3333
private static final Pattern S3_ENDPOINT_PATTERN =
3434
Pattern.compile("^(?:.+\\.)?s3[.-]([a-z0-9-]+)$");
35+
36+
private static final String VPC_NAME = "vpce";
3537

3638
/**
3739
* @deprecated in favor of {@link #parseRegionName(String, String)}.
@@ -117,8 +119,18 @@ private static String parseStandardRegionName(final String fragment) {
117119
return "us-east-1";
118120
}
119121

120-
// host was 'service.[region].amazonaws.com'.
122+
// host was 'service.[region].amazonaws.com'. or 'service.[region].vpce.amazonaws.com'
121123
String region = fragment.substring(index + 1);
124+
if (region.equals(VPC_NAME)) {
125+
String[] partsOfFragment = fragment.split("\\.");
126+
if (partsOfFragment.length >= 2) {
127+
// host was 'service.[region].vpce.amazonaws.com'
128+
region = partsOfFragment[partsOfFragment.length - 2];
129+
} else {
130+
// guess us-east-1 for lack of a better option
131+
return "us-east-1";
132+
}
133+
}
122134

123135
// Special case for iam.us-gov.amazonaws.com, which is actually
124136
// us-gov-west-1.

aws-android-sdk-core/src/test/java/com/amazonaws/util/AwsHostNameUtilsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public void testStandard() {
9494
"bucket.name.with.periods.s3.eu-west-1.amazonaws.com", "s3"));
9595
}
9696

97+
@Test
98+
public void testVpcEndpoint() {
99+
assertEquals("us-west-2", AwsHostNameUtils.parseRegionName(
100+
"bucket.vpce-1234.s3.us-west-2.vpce.amazonaws.com", "s3"));
101+
}
102+
97103
@Test
98104
public void testBJS() {
99105
// Verify that BJS endpoints parse correctly even though they're

0 commit comments

Comments
 (0)