现在是否有一种方法可以获取"AWS区域名称"?在boto3中? [英] Is there now a way to get "AWS region names" in boto3?
问题描述
boto3
中现在是否存在将 AWS区域代码转换为 AWS区域名称的方法,例如将('us-west-1', 'us-east-1', 'us-west-2')
转换为('N. California', 'N. Virginia', 'Oregon')
? >
我可以使用以下代码段获取 AWS地区代码的列表:
from boto3.session import Session
s = Session()
regions = s.get_available_regions('rds')
print("regions:", regions)
$ python3 regions.py
regions: ['ap-northeast-1', 'ap-northeast-2', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2']
是否存在等效的代码段,可以给我 AWS区域名称?
AWS刚刚发布了一项功能,该功能允许使用AWS Systems Manager参数存储查询AWS区域,端点和更多信息.
使用此功能和boto3
,您可以执行以下操作:
import boto3
client = boto3.client('ssm')
response = client.get_parameter(
Name='/aws/service/global-infrastructure/regions/us-west-1/longName'
)
region_name = response['Parameter']['Value'] # US West (N. California)
要获取所有可用区域,您可以先使用get_parameters_by_path()
并使用以下路径/aws/service/global-infrastructure/regions
.
注意:即使这是公共数据,也需要适当的IAM权限.
Is there now a way in boto3
to convert AWS region codes to AWS region names, e.g to convert ('us-west-1', 'us-east-1', 'us-west-2')
to ('N. California', 'N. Virginia', 'Oregon')
?
I can get a list of AWS region codes with the following snippet:
from boto3.session import Session
s = Session()
regions = s.get_available_regions('rds')
print("regions:", regions)
$ python3 regions.py
regions: ['ap-northeast-1', 'ap-northeast-2', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2']
Is there an equivalent snippet that would give me the AWS region names?
AWS just released a feature that allows to query for AWS Regions, Endpoints, and More Using AWS Systems Manager Parameter Store.
Using this feature and boto3
, you can do something like this:
import boto3
client = boto3.client('ssm')
response = client.get_parameter(
Name='/aws/service/global-infrastructure/regions/us-west-1/longName'
)
region_name = response['Parameter']['Value'] # US West (N. California)
To get all available regions you can first use get_parameters_by_path()
using the following path /aws/service/global-infrastructure/regions
.
Note: even though this is public data, it requires proper IAM permissions.
这篇关于现在是否有一种方法可以获取"AWS区域名称"?在boto3中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!