File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
main/java/com/amazonaws/util
test/java/com/amazonaws/util Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments