I'd like to see how I can get a list of regions from AWS on the command line so I can quickly look things up, how can I do this?
3 Answers
This is now how you'd do it using the aws cli:
$ aws ec2 describe-regions --output table
----------------------------------------------------------
| DescribeRegions |
+--------------------------------------------------------+
|| Regions ||
|+-----------------------------------+------------------+|
|| Endpoint | RegionName ||
|+-----------------------------------+------------------+|
|| ec2.eu-west-1.amazonaws.com | eu-west-1 ||
|| ec2.ap-southeast-1.amazonaws.com | ap-southeast-1 ||
|| ec2.ap-southeast-2.amazonaws.com | ap-southeast-2 ||
|| ec2.eu-central-1.amazonaws.com | eu-central-1 ||
|| ec2.ap-northeast-2.amazonaws.com | ap-northeast-2 ||
|| ec2.ap-northeast-1.amazonaws.com | ap-northeast-1 ||
|| ec2.us-east-1.amazonaws.com | us-east-1 ||
|| ec2.sa-east-1.amazonaws.com | sa-east-1 ||
|| ec2.us-west-1.amazonaws.com | us-west-1 ||
|| ec2.us-west-2.amazonaws.com | us-west-2 ||
|+-----------------------------------+------------------+|
You can do this by running the command ec2-describe-regions from the command line (if you have ec2-api-tools installed available in multiverse).
$ ec2-describe-regions
REGION eu-west-1 ec2.eu-west-1.amazonaws.com
REGION sa-east-1 ec2.sa-east-1.amazonaws.com
REGION us-east-1 ec2.us-east-1.amazonaws.com
REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com
REGION us-west-2 ec2.us-west-2.amazonaws.com
REGION us-west-1 ec2.us-west-1.amazonaws.com
REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com
-
2Yeah, about that. You need a default region configured before this will work (3 years later, still ?). So google is your friend. Regions and endpoints (rande - nmemonically randy) here docs.aws.amazon.com/general/latest/gr/rande.html. Why they could not just default to us-east-1 when this is attempted before configuration is beyond me ?– mckenzmJan 1, 2016 at 0:40
-
@mckenzm lol "rande - mnemonically randy" I thought that was just something happening inside my head. Google probably has a laugh at the number of times I've googled "amazon rande". I assume the reason for not using a default endpoint is that it would put much the burden on that one single region's endpoints, and would be unnecessarily slow for a large percentage of users who are closer to another region. It also might be related to the flow of logic inside aws-cli -- perhaps the "ec2" part requires endpoint selection before "describe-regions" is actually understood. Wild guesses. Dec 8, 2017 at 13:41
-
You need a default region configured before this will work
any way to get the region without specifying any region? Aug 17, 2020 at 12:42
Botocore would have all of them in configured endpoints:
$ curl -s https://raw.githubusercontent.com/boto/botocore/develop/botocore/data/endpoints.json | grep -B1 desc|grep {|cut -d \" -f2
Your AWS CLI installation may have it locally; In this example, I get at it with python:
$ python3 << :]
> #!/usr/bin/env python3.7
>
> import botocore, json
> from pathlib import Path
>
> with open("{}/{}".format(Path(botocore.__file__).resolve().parent, "data/endpoints.json"), 'r') as e:
> for p in json.load(e)['partitions']:
> print("{}:\t\t{}".format(p['partitionName']," ".join(p['regions'].keys())))
> :]
AWS Standard: af-south-1 ap-east-1 ap-northeast-1 ap-northeast-2 ap-northeast-3 ap-south-1 ap-southeast-1 ap-southeast-2 ap-southeast-3 ca-central-1 eu-central-1 eu-north-1 eu-south-1 eu-west-1 eu-west-2 eu-west-3 me-south-1 sa-east-1 us-east-1 us-east-2 us-west-1 us-west-2
AWS China: cn-north-1 cn-northwest-1
AWS GovCloud (US): us-gov-east-1 us-gov-west-1
AWS ISO (US): us-iso-east-1 us-iso-west-1
AWS ISOB (US): us-isob-east-1