如何通过命令行获取亚马逊地区列表?

我想了解如何在命令行中从AWS获取区域列表,以便快速查找信息,我应该怎么做?

3个回答

这是使用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       ||
|+-----------------------------------+------------------+|

你可以通过在命令行中运行命令ec2-describe-regions来完成此操作(如果你已经安装了multiverse中可用的ec2-api-tools)。
$ 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

2是的,关于这个问题。在此之前,您需要配置一个默认区域才能使其正常工作(三年后,仍然如此?)。所以谷歌是你的朋友。区域和终端节点(rande - 用来记忆的是randy)在这里:http://docs.aws.amazon.com/general/latest/gr/rande.html。为什么他们不能在配置之前默认为us-east-1,这超出了我的理解范围。 - mckenzm
@mckenzm 哈哈,“rande - mnemonically randy”,我以为那只是发生在我的脑海里的事情。Google可能会因为我搜索“amazon rande”的次数而笑。我认为不使用默认端点的原因是它会给那个单一区域的端点带来很大的负担,并且对于更接近另一个区域的大多数用户来说,速度会变得非常慢。这也可能与aws-cli内部的逻辑流有关--也许“ec2”部分需要在实际理解“describe-regions”之前选择端点。猜测而已。 - Michael - sqlbot
在此之前,您需要配置一个默认区域才能使其正常工作。有没有办法在不指定任何区域的情况下获取区域信息? - Suncatcher

Botocore会将它们全部配置在端点中:

$ curl -s https://raw.githubusercontent.com/boto/botocore/develop/botocore/data/endpoints.json | grep -B1 desc|grep {|cut -d \" -f2

你的AWS CLI安装可能已经在本地了;在这个例子中,我用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