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

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

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

答案1

现在你可以按照以下方式使用 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       ||
|+-----------------------------------+------------------+|

答案2

您可以通过运行命令来执行此操作ec2-描述-区域从命令行(如果您已经在 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

答案3

博托科会将它们全部放置在已配置的端点中:

$ 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

相关内容