1
15 package com.amazonaws.regions;
16
17 import com.amazonaws.AmazonClientException;
18 import org.apache.commons.logging.LogFactory;
19
20 import com.amazonaws.util.EC2MetadataUtils;
21
22
25 public enum Regions {
26
27 GovCloud("us-gov-west-1", "AWS GovCloud (US)"),
28 US_GOV_EAST_1("us-gov-east-1", "AWS GovCloud (US-East)"),
29 US_EAST_1("us-east-1", "US East (N. Virginia)"),
30 US_EAST_2("us-east-2", "US East (Ohio)"),
31 US_WEST_1("us-west-1", "US West (N. California)"),
32 US_WEST_2("us-west-2", "US West (Oregon)"),
33 EU_WEST_1("eu-west-1", "EU (Ireland)"),
34 EU_WEST_2("eu-west-2", "EU (London)"),
35 EU_WEST_3("eu-west-3", "EU (Paris)"),
36 EU_CENTRAL_1("eu-central-1", "EU (Frankfurt)"),
37 EU_NORTH_1("eu-north-1", "EU (Stockholm)"),
38 EU_SOUTH_1("eu-south-1", "EU (Milan)"),
39 AP_EAST_1("ap-east-1", "Asia Pacific (Hong Kong)"),
40 AP_SOUTH_1("ap-south-1", "Asia Pacific (Mumbai)"),
41 AP_SOUTHEAST_1("ap-southeast-1", "Asia Pacific (Singapore)"),
42 AP_SOUTHEAST_2("ap-southeast-2", "Asia Pacific (Sydney)"),
43 AP_NORTHEAST_1("ap-northeast-1", "Asia Pacific (Tokyo)"),
44 AP_NORTHEAST_2("ap-northeast-2", "Asia Pacific (Seoul)"),
45 SA_EAST_1("sa-east-1", "South America (Sao Paulo)"),
46 CN_NORTH_1("cn-north-1", "China (Beijing)"),
47 CN_NORTHWEST_1("cn-northwest-1", "China (Ningxia)"),
48 CA_CENTRAL_1("ca-central-1", "Canada (Central)"),
49 ME_SOUTH_1("me-south-1", "Middle East (Bahrain)"),
50 AF_SOUTH_1("af-south-1", "Africa (Cape Town)")
51 ;
52
53
57 public static final Regions DEFAULT_REGION = US_WEST_2;
58
59 private final String name;
60 private final String description;
61
62 private Regions(String name, String description) {
63 this.name = name;
64 this.description = description;
65 }
66
67
70 public String getName() {
71 return name;
72 }
73
74
77 public String getDescription() {
78 return description;
79 }
80
81
88 public static Regions fromName(String regionName) {
89 for (Regions region : Regions.values()) {
90 if (region.getName().equals(regionName)) {
91 return region;
92 }
93 }
94 throw new IllegalArgumentException("Cannot create enum from " + regionName + " value!");
95 }
96
97
102 public static Region getCurrentRegion() {
103 try {
104 final String region = EC2MetadataUtils.getEC2InstanceRegion();
105 if (region != null)
106 return RegionUtils.getRegion(region);
107 } catch (AmazonClientException e) {
108 LogFactory.getLog(Regions.class).debug(
109 "Ignoring failure to retrieve the region: " + e.getMessage());
110 }
111 return null;
112 }
113 }
114