AwsHostNameUtils { @Deprecated public static String parseRegionName(URI endpoint) { return parseRegionName(endpoint.getHost(), null); }  @Deprecated static String parseRegionName(URI endpoint); @Deprecated static String parseRegionName(final String host,
                                         final String serviceHint); static String parseRegion(String host, String serviceHint); @SdkProtectedApi static String parseRegionFromInternalConfig(String host); @SdkProtectedApi static String parseRegionFromAwsPartitionPattern(String host); @SdkProtectedApi static String parseRegionUsingServiceHint(String host, String serviceHint); static String parseRegionFromAfterServiceName(String host, String serviceHint); @Deprecated static String parseServiceName(URI endpoint); static String localHostName();  }
@Test public void testStandardNoHint() { assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("iam.amazonaws.com", null)); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("iam.us-west-2.amazonaws.com", null)); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("ec2.us-west-2.amazonaws.com", null)); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("s3.amazonaws.com", null)); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("bucket.name.s3.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3-eu-west-1.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3.eu-west-1.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("bucket.name.with.periods.s3-eu-west-1.amazonaws.com", null)); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("bucket.name.with.periods.s3.eu-west-1.amazonaws.com", null)); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("cloudsearch.us-west-2.amazonaws.com", null)); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("domain.us-west-2.cloudsearch.amazonaws.com", null)); }
@Test public void testStandard() { assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("iam.amazonaws.com", "iam")); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("iam.us-west-2.amazonaws.com", "iam")); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("ec2.us-west-2.amazonaws.com", "ec2")); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("s3.amazonaws.com", "s3")); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("bucket.name.s3.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("s3.eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("bucket.name.with.periods.s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", AwsHostNameUtils.parseRegionName("bucket.name.with.periods.s3.eu-west-1.amazonaws.com", "s3")); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("cloudsearch.us-west-2.amazonaws.com", "cloudsearch")); assertEquals("us-west-2", AwsHostNameUtils.parseRegionName("domain.us-west-2.cloudsearch.amazonaws.com", "cloudsearch")); }
@Test public void testBJS() { assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("iam.cn-north-1.amazonaws.com.cn", "iam")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("ec2.cn-north-1.amazonaws.com.cn", "ec2")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("s3.cn-north-1.amazonaws.com.cn", "s3")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("bucket.name.with.periods.s3.cn-north-1.amazonaws.com.cn", "s3")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("cloudsearch.cn-north-1.amazonaws.com.cn", "cloudsearch")); assertEquals("cn-north-1", AwsHostNameUtils.parseRegionName("domain.cn-north-1.cloudsearch.amazonaws.com.cn", "cloudsearch")); }
@Test public void testS3SpecialRegions() { assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("s3-external-1.amazonaws.com", null)); assertEquals("us-east-1", AwsHostNameUtils.parseRegionName("bucket.name.with.periods.s3-external-1.amazonaws.com", null)); assertEquals("us-gov-west-1", AwsHostNameUtils.parseRegionName("s3-fips-us-gov-west-1.amazonaws.com", null)); assertEquals("us-gov-west-1", AwsHostNameUtils.parseRegionName("bucket.name.with.periods.s3-fips-us-gov-west-1.amazonaws.com", null)); }