1 /*
2  * Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5  * the License. A copy of the License is located at
6  * 
7  * http://aws.amazon.com/apache2.0
8  * 
9  * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10  * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11  * and limitations under the License.
12  */

13
14 package software.amazon.awssdk.regions;
15
16 import java.util.Arrays;
17 import java.util.Collections;
18 import java.util.List;
19 import java.util.concurrent.ConcurrentHashMap;
20 import software.amazon.awssdk.annotations.Generated;
21 import software.amazon.awssdk.annotations.SdkPublicApi;
22 import software.amazon.awssdk.utils.Validate;
23 import software.amazon.awssdk.utils.http.SdkHttpUtils;
24
25 /**
26  * An Amazon Web Services region that hosts a set of Amazon services.
27  * <p>
28  * An instance of this class can be retrieved by referencing one of the static constants defined in this class (eg.
29  * {@link Region#US_EAST_1}) or by using the {@link Region#of(String)} method if the region you want is not included in
30  * this release of the SDK.
31  * </p>
32  * <p>
33  * Each AWS region corresponds to a separate geographical location where a set of Amazon services is deployed. These
34  * regions (except for the special {@link #AWS_GLOBAL} and {@link #AWS_CN_GLOBAL} regions) are separate from each other,
35  * with their own set of resources. This means a resource created in one region (eg. an SQS queue) is not available in
36  * another region.
37  * </p>
38  * <p>
39  * To programmatically determine whether a particular service is deployed to a region, you can use the
40  * {@code serviceMetadata} method on the service's client interface. Additional metadata about a region can be
41  * discovered using {@link RegionMetadata#of(Region)}.
42  * </p>
43  * <p>
44  * The {@link Region#id()} will be used as the signing region for all requests to AWS services unless an explicit region
45  * override is available in {@link RegionMetadata}. This id will also be used to construct the endpoint for accessing a
46  * service unless an explicit endpoint is available for that region in {@link RegionMetadata}.
47  * </p>
48  */

49 @SdkPublicApi
50 @Generated("software.amazon.awssdk:codegen")
51 public final class Region {
52     public static final Region AP_SOUTH_1 = Region.of("ap-south-1");
53
54     public static final Region EU_SOUTH_1 = Region.of("eu-south-1");
55
56     public static final Region US_GOV_EAST_1 = Region.of("us-gov-east-1");
57
58     public static final Region CA_CENTRAL_1 = Region.of("ca-central-1");
59
60     public static final Region EU_CENTRAL_1 = Region.of("eu-central-1");
61
62     public static final Region US_WEST_1 = Region.of("us-west-1");
63
64     public static final Region US_WEST_2 = Region.of("us-west-2");
65
66     public static final Region AF_SOUTH_1 = Region.of("af-south-1");
67
68     public static final Region EU_NORTH_1 = Region.of("eu-north-1");
69
70     public static final Region EU_WEST_3 = Region.of("eu-west-3");
71
72     public static final Region EU_WEST_2 = Region.of("eu-west-2");
73
74     public static final Region EU_WEST_1 = Region.of("eu-west-1");
75
76     public static final Region AP_NORTHEAST_2 = Region.of("ap-northeast-2");
77
78     public static final Region AP_NORTHEAST_1 = Region.of("ap-northeast-1");
79
80     public static final Region ME_SOUTH_1 = Region.of("me-south-1");
81
82     public static final Region SA_EAST_1 = Region.of("sa-east-1");
83
84     public static final Region AP_EAST_1 = Region.of("ap-east-1");
85
86     public static final Region CN_NORTH_1 = Region.of("cn-north-1");
87
88     public static final Region US_GOV_WEST_1 = Region.of("us-gov-west-1");
89
90     public static final Region AP_SOUTHEAST_1 = Region.of("ap-southeast-1");
91
92     public static final Region AP_SOUTHEAST_2 = Region.of("ap-southeast-2");
93
94     public static final Region US_ISO_EAST_1 = Region.of("us-iso-east-1");
95
96     public static final Region US_EAST_1 = Region.of("us-east-1");
97
98     public static final Region US_EAST_2 = Region.of("us-east-2");
99
100     public static final Region CN_NORTHWEST_1 = Region.of("cn-northwest-1");
101
102     public static final Region US_ISOB_EAST_1 = Region.of("us-isob-east-1");
103
104     public static final Region AWS_GLOBAL = Region.of("aws-global"true);
105
106     public static final Region AWS_CN_GLOBAL = Region.of("aws-cn-global"true);
107
108     public static final Region AWS_US_GOV_GLOBAL = Region.of("aws-us-gov-global"true);
109
110     public static final Region AWS_ISO_GLOBAL = Region.of("aws-iso-global"true);
111
112     public static final Region AWS_ISO_B_GLOBAL = Region.of("aws-iso-b-global"true);
113
114     private static final List<Region> REGIONS = Collections.unmodifiableList(Arrays.asList(AP_SOUTH_1, EU_SOUTH_1, US_GOV_EAST_1,
115             CA_CENTRAL_1, EU_CENTRAL_1, US_WEST_1, US_WEST_2, AF_SOUTH_1, EU_NORTH_1, EU_WEST_3, EU_WEST_2, EU_WEST_1,
116             AP_NORTHEAST_2, AP_NORTHEAST_1, ME_SOUTH_1, SA_EAST_1, AP_EAST_1, CN_NORTH_1, US_GOV_WEST_1, AP_SOUTHEAST_1,
117             AP_SOUTHEAST_2, US_ISO_EAST_1, US_EAST_1, US_EAST_2, CN_NORTHWEST_1, US_ISOB_EAST_1, AWS_GLOBAL, AWS_CN_GLOBAL,
118             AWS_US_GOV_GLOBAL, AWS_ISO_GLOBAL, AWS_ISO_B_GLOBAL));
119
120     private final boolean isGlobalRegion;
121
122     private final String id;
123
124     private Region(String id, boolean isGlobalRegion) {
125         this.id = id;
126         this.isGlobalRegion = isGlobalRegion;
127     }
128
129     public static Region of(String value) {
130         return of(value, false);
131     }
132
133     private static Region of(String value, boolean isGlobalRegion) {
134         Validate.paramNotBlank(value, "region");
135         String urlEncodedValue = SdkHttpUtils.urlEncode(value);
136         return RegionCache.put(urlEncodedValue, isGlobalRegion);
137     }
138
139     public static List<Region> regions() {
140         return REGIONS;
141     }
142
143     public String id() {
144         return this.id;
145     }
146
147     public RegionMetadata metadata() {
148         return RegionMetadata.of(this);
149     }
150
151     public boolean isGlobalRegion() {
152         return isGlobalRegion;
153     }
154
155     @Override
156     public String toString() {
157         return id;
158     }
159
160     private static class RegionCache {
161         private static final ConcurrentHashMap<String, Region> VALUES = new ConcurrentHashMap<>();
162
163         private RegionCache() {
164         }
165
166         private static Region put(String value, boolean isGlobalRegion) {
167             return VALUES.computeIfAbsent(value, v -> new Region(value, isGlobalRegion));
168         }
169     }
170 }
171