'How should i get aws region names using regions
Hi I want to get the amazon web services(aws) region names using regions means
region is "us-east-1" region name is "US East (N. Virginia)"
region is "us-west-2" region name is "US West (Oregon)"
using us-east-1 region i want to display region name "US East (N. Virginia)" dynamically.
Thanks Sanjay
Solution 1:[1]
There isn't an AWS API method to call to get this information.
Some SDKs, such as the AWS SDK for .NET has this information baked into the SDK. For example, in C#:
var regions = Amazon.RegionEndpoint.EnumerableAllRegions;
foreach (var r in regions)
{
Console.WriteLine("{0} -> {1}", r.SystemName, r.DisplayName);
}
Looking through the docs for the AWS SDK for Java, I am not finding an equivalent. If it were there, I would think it should be on the com.amazonaws.regions.Region class.
You may have to create your own mapping.
Solution 2:[2]
Turns out that this is actually provided via LightSail - makes sense to include information for the less experienced in a service catering mainly to new-arrivals.
aws lightsail get-regions
{
"regions": [
{
"continentCode": "NA",
"description": "This region is recommended to serve users in the eastern United States and eastern Canada",
"displayName": "Virginia",
"name": "us-east-1",
"availabilityZones": []
},
....
OP probably isn't looking for the answer anymore, but in case somebody's googling.
Solution 3:[3]
For language independent implementation, here is (hopefully) up to date JSON with all the regions (at least ones available for my own account in early 2020). As other answers agree there is no programmatic way to achieve this, so only way to go is manually building a map of region names and respective friendly names.
{
"ap-northeast-1": "Asia Pacific (Tokyo)",
"ap-northeast-2": "Asia Pacific (Seoul)",
"ap-southeast-1": "Asia Pacific (Singapore)",
"ap-southeast-2": "Asia Pacific (Sydney)",
"ap-south-1": "Asia Pacific (Mumbai)",
"eu-central-1": "EU (Frankfurt)",
"eu-north-1": "Europe (Stockholm)",
"eu-west-1": "EU (Ireland)",
"eu-west-2": "Europe (London)",
"eu-west-3": "Europe (Paris)",
"us-east-1": "US East (N. Virginia)",
"us-east-2": "US East (Ohio)",
"us-west-1": "US West (N. California)",
"us-west-2": "US West (Oregon)",
"sa-east-1": "South America (Sao Paulo)",
"ca-central-1": "Canada (Central)"
}
For instance, ruby implementation would look like
require 'json'
require 'aws-sdk-ec2'
data = JSON.load File.read 'regions.json'
all_regions = Aws::EC2::Client.new.describe_regions.regions
all_regions.each { |r| puts "#{data[r.region_name]} - #{r.region_name}" }
Solution 4:[4]
The java AWS client has a Regions class that will give this information, for example:
for(Regions region : Regions.getEnumConstants()) {
System.out.println( String.sprintf("%-15s %s", region.getName(), (Regions.fromName(region.getName())).getDescription()))
}
Outputs:
us-gov-west-1 AWS GovCloud (US)
us-gov-east-1 AWS GovCloud (US-East)
us-east-1 US East (N. Virginia)
us-east-2 US East (Ohio)
us-west-1 US West (N. California)
us-west-2 US West (Oregon)
eu-west-1 EU (Ireland)
eu-west-2 EU (London)
eu-west-3 EU (Paris)
eu-central-1 EU (Frankfurt)
eu-north-1 EU (Stockholm)
ap-south-1 Asia Pacific (Mumbai)
ap-southeast-1 Asia Pacific (Singapore)
ap-southeast-2 Asia Pacific (Sydney)
ap-northeast-1 Asia Pacific (Tokyo)
ap-northeast-2 Asia Pacific (Seoul)
sa-east-1 South America (Sao Paulo)
cn-north-1 China (Beijing)
cn-northwest-1 China (Ningxia)
ca-central-1 Canada (Central)
For my aws sdk client, I'm using
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.537</version>
</dependency>
Solution 5:[5]
Kindly run below command to list AWS regions with Endpoint URL.
aws ec2 describe-regions --region us-east-1
Solution 6:[6]
Check this sample CLI command "aws ec2 describe-regions --filters "Name=endpoint,Values=us"". You need to use JQ or --query option to extract the Region name alone.
More details here - http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-regions.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matt Houser |
| Solution 2 | Bent Terp |
| Solution 3 | toske |
| Solution 4 | GregG |
| Solution 5 | linux.cnf |
| Solution 6 | Shankar P S |
