8
votes

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

5

5 Answers

7
votes

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.

1
votes

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.

1
votes

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}" }
0
votes

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

0
votes

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>