9

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

Sanjay Kumar
  • 309
  • 2
  • 5
  • 9

7 Answers7

8

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.

Matt Houser
  • 33,983
  • 6
  • 70
  • 88
  • Still no way to get friendly names except C#? – Suncatcher Aug 17 '17 at 08:14
  • 1
    Please be aware that SDK's `DisplayName` is different from one used in AWS. For example, it's `US East (Virginia)` in SDK, but `US East (N. Virginia)` everywhere else. – STiLeTT Aug 28 '18 at 09:36
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.

Bent Terp
  • 31
  • 1
  • `aws lightsail get-regions` is returning an incomplete list of regions – chriscatfr Apr 08 '18 at 10:05
  • @chriscatfr just an fyi for future viewers, you need to hit enter for the rest of the information to display – dko Nov 21 '21 at 23:43
  • thanks @dko . if you use aws cli v2 there's still the option `--no-cli-pager` I think – chriscatfr Nov 26 '21 at 17:35
  • @dko It's not about pagination `aws lightsail get-regions --no-paginate | jq '.regions | length'` returns `14`. There's not even an entry for `us-west-1`. This is because Lightsail is not available in all regions. – Old Pro Sep 26 '22 at 02:16
1

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}" }
toske
  • 1,744
  • 13
  • 24
0

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>
GregG
  • 781
  • 1
  • 6
  • 10
0

Found a way to get the (complete?) list programmatically, although it took me a few commands. This should work with bash or zsh, should be easy to adapt elsewhere.

It's unfortunately quite slow; parallelizing the call to aws pricing would help. Finding the magic product that has exactly one SKU in every region would be even better, but I have no idea what that SKU might be.

[Also, I'm on a Mac, so (1) these are probably the BSD-ish versions of things like sed; and (2) I'm stuck on Bash3, so I'm being pretty basic in my usage.]

# Get list of regions codes.
all_regions=( $( aws pricing get-attribute-values \
                     --region us-east-1           \
                     --service-code AmazonEC2     \
                     --attribute-name regionCode  \
                     --output text                \
                     --query AttributeValues ) )

# Fetch one product from each, grab out the human-friendly location.
# This is a bit slow (took about 90s here).
typeset -a all_regions_and_names
all_regions_and_names=()
for region in "${all_regions[@]}"
do
  region_and_name=$(                                                     \
    aws pricing get-products                                             \
        --region        us-east-1                                        \
        --service-code  AmazonEC2                                        \
        --filters       "Type=TERM_MATCH,Field=regionCode,Value=$region" \
        --max-items     1                                                \
    | jq -rc '.PriceList[]'                                              \
    | jq -r '.product.attributes | "\(.regionCode)=\(.location)"'
  )
  all_regions_and_names+=( $region_and_name )
done

Once you have that (array) variable, it's easy to turn it into a text table:

( echo "region=name"
  echo "----------------------=------------------------------"
  IFS=$'\n'
  echo "${all_regions_and_names[*]}" | sort | uniq
) \
| column -s = -t

Sample output:

region                   name
----------------------   ------------------------------
af-south-1-los-1         Nigeria (Lagos)
af-south-1               Africa (Cape Town)
ap-east-1                Asia Pacific (Hong Kong)
...

Or into JSON:

echo '{'
(
  IFS=$'\n'
  echo "${all_regions_and_names[*]}" | sort | uniq
) \
| sed -E -e 's/^(.*)=(.*)$/  "\1":="\2",/' \
         -e '$,$ s/,$//' \
| column -t -s =
echo '}'

Sample output:

{
  "af-south-1-los-1":         "Nigeria (Lagos)",
  "af-south-1":               "Africa (Cape Town)",
  "ap-east-1":                "Asia Pacific (Hong Kong)",
  ...
}

Note that the pricing API is only available in us-east-1 and ap-south-1 hence the --region option above (which only controls the AWS API endpoint used; it does not narrow the query itself at all.)

(It could be done in a single command if someone knows of a single product that is available in every region and local zone. Alternately, you could ask it to list everything available under a particular serviceCode, but that gets huge fast -- hence my simple --max-items 1 workaround above.)

Even this might not be complete, if there are zones which don't offer EC2 instances at all. Hopefully you're ultimately trying to answer the question "where can I get an X and what do I have to call the region I'm trying to get one", so you can just adjust the serviceCode.

Hat tip to How to get ec2 instance details with price details using aws cli which got me started down this path.

AnthonyFoiani
  • 504
  • 5
  • 7
-1

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

Shankar
  • 2,625
  • 3
  • 25
  • 49
-1

Kindly run below command to list AWS regions with Endpoint URL.

aws ec2 describe-regions --region us-east-1
linux.cnf
  • 519
  • 6
  • 7