Reputation: 2662
I can't find a way to retrieve the English names of regions with AWS CLI. Any idea?
I need to generate the following table of English names of all AWS regions in command line output in Linux.
'ap-northeast-1' => 'Asia Pacific (Tokyo)',
'ap-southeast-1' => 'Asia Pacific (Singapore)',
'ap-southeast-2' => 'Asia Pacific (Sydney)',
'eu-central-1' => 'EU (Frankfurt)',
'eu-west-1' => 'EU (Ireland)',
'sa-east-1' => 'South America (Sao Paulo)',
'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-2' => 'EU (London)',
'ca-central-1' => 'Canada (Central)',
'sa-east-1' => 'South America (Sao Paulo)',
I am not admin for the linux VMs and can't install Java.
Upvotes: 7
Views: 1316
Reputation: 1602
Even though this is kind of old I think the correct answer for the question which stated the need for generating a table with the regions and their English names without relaying in the documentation format hasn't been addressed correctly. I go with two AWS CLI commands on a loop like this:
#!/bin/bash
fmt="%-16s%-4s%-25s\n"
for i in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text)
do
printf "$fmt" "'$i" "=>" "$(aws ssm get-parameter --name /aws/service/global-infrastructure/regions/$i/longName --query "Parameter.Value" --output text)',"
done
Upvotes: 3
Reputation: 134
Also encountered this issue, found this AWS article saying you can query all kind of data using AWS Parameter Store. after digging a little found this solution using AWS CLI
region=us-east-1
aws ssm get-parameter --name /aws/service/global-infrastructure/regions/$region/longName --query "Parameter.Value" --output text
Upvotes: 3
Reputation: 9
I have a similar issue, solved the issue with the code below:
REGION_TARGET=us-east-1
region_name=$(wget -qO- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html\#concepts-available-regions | awk NF | awk -v pat="<p><code class=\"code\">$TARGET_REGION" '$0 ~ pat {for(i=0;i<5;i++) {getline; print}}' | awk -F'[<|>]' '/<p>|<\/p>/ {print $3}');
Upvotes: 0
Reputation: 1192
UPDATE: AWS recently revamp their documentation site, which caused this solution to stop working. I've updated the code below to make it work again. Please keep in mind that any changes to structure of the AWS documentation site in the future might result in it not working again. This is simply a workaround.
Based on the @jarmod's comment how about something like this:
Function:
Example Code (BASH):
function getAWSRegionName {
tmp=$(wget -qO- https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.partial.html | awk NF | awk -v pat="<p><code class=\"code\">$1" '$0 ~ pat {for(i=0;i<5;i++) {getline; print}}' | awk -F'[<|>]' '/<p>|<\/p>/ {print $3}');
echo "$1 = $tmp";
}
for code in `aws ec2 describe-regions | awk -F'"' '/RegionName/{print $4}'`; do
getAWSRegionName $code;
done
Result:
Upvotes: 3