Есть ли теперь способ получить все «имена регионов AWS» для RDS, в boto3? - PullRequest
0 голосов
/ 01 мая 2019

Я пытаюсь получить все Имена регионов AWS для RDS, используя boto3.
Однако, похоже, что ответы, которые я получаю, зависят от региона, который я запрашиваю.

Мой скрипт:

$ cat so_regions2.py                                                                                                                                                         
import boto3

region = "us-west-1"
region = "us-east-1"

print("Using region:", region)
rds = boto3.setup_default_session(region_name=region)
client = boto3.client("rds")
rds_responses = client.describe_source_regions()['SourceRegions']

ssm_client = boto3.client('ssm', region_name=region)
for resp in rds_responses:
    region_id = resp['RegionName']
    tmp = '/aws/service/global-infrastructure/regions/%s/longName' % region_id
    ssm_response = ssm_client.get_parameter(Name = tmp)
    region_name = ssm_response['Parameter']['Value'] 
    print ("region_id:",region_id,"region_name:",region_name)

И когда я запускаю его, я получаю:

$ python3 so_regions2.py                                                                                                                                                     
Using region: us-east-1
region_id: ap-northeast-1 region_name: Asia Pacific (Tokyo)
region_id: ap-northeast-2 region_name: Asia Pacific (Seoul)
region_id: ap-south-1 region_name: Asia Pacific (Mumbai)
region_id: ap-southeast-1 region_name: Asia Pacific (Singapore)
region_id: ap-southeast-2 region_name: Asia Pacific (Sydney)
region_id: eu-central-1 region_name: EU (Frankfurt)
region_id: eu-west-1 region_name: EU (Ireland)
region_id: eu-west-2 region_name: EU (London)
region_id: sa-east-1 region_name: South America (Sao Paulo)
region_id: us-west-1 region_name: US West (N. California)
region_id: us-west-2 region_name: US West (Oregon)

Однако, если я изменю название региона, я получу другие результаты (обратите внимание на последнюю, кроме одной строки):

$ python3 so_regions2.py
Using region: us-west-1
region_id: ap-northeast-1 region_name: Asia Pacific (Tokyo)
region_id: ap-northeast-2 region_name: Asia Pacific (Seoul)
region_id: ap-south-1 region_name: Asia Pacific (Mumbai)
region_id: ap-southeast-1 region_name: Asia Pacific (Singapore)
region_id: ap-southeast-2 region_name: Asia Pacific (Sydney)
region_id: eu-central-1 region_name: EU (Frankfurt)
region_id: eu-west-1 region_name: EU (Ireland)
region_id: eu-west-2 region_name: EU (London)
region_id: sa-east-1 region_name: South America (Sao Paulo)
region_id: us-east-1 region_name: US East (N. Virginia)
region_id: us-west-2 region_name: US West (Oregon)

$ python3 so_regions2.py
Using region: ap-northeast-1
region_id: ap-northeast-2 region_name: Asia Pacific (Seoul)
region_id: ap-south-1 region_name: Asia Pacific (Mumbai)
region_id: ap-southeast-1 region_name: Asia Pacific (Singapore)
region_id: ap-southeast-2 region_name: Asia Pacific (Sydney)
region_id: eu-central-1 region_name: EU (Frankfurt)
region_id: eu-west-1 region_name: EU (Ireland)
region_id: eu-west-2 region_name: EU (London)
region_id: sa-east-1 region_name: South America (Sao Paulo)
region_id: us-east-1 region_name: US East (N. Virginia)
region_id: us-west-1 region_name: US West (N. California)
region_id: us-west-2 region_name: US West (Oregon)

Есть ли способ получить все имена регионов AWS для RDS, используя boto3?

1 Ответ

0 голосов
/ 01 мая 2019

Код должен быть изменен, как указано ниже.

import boto3

#region = "us-west-1" # 
region = "us-east-1" # this effectively assigning us-east-1 to region in any case.

print("Using region:", region)
#rds = boto3.setup_default_session(region_name=region)
client = boto3.client("rds",region_name=region)
rds_responses = client.describe_source_regions()['SourceRegions']

ssm_client = boto3.client('ssm', region_name=region)
for resp in rds_responses:
    region_id = resp['RegionName']
    tmp = '/aws/service/global-infrastructure/regions/%s/longName' % region_id
    ssm_response = ssm_client.get_parameter(Name = tmp)
    region_name = ssm_response['Parameter']['Value'] 
    print ("region_id:",region_id,"region_name:",region_name)

измененные строки

#region = "us-west-1" # 
region = "us-east-1" # this effectively assigning us-east-1 to region in any case.

#rds = boto3.setup_default_session(region_name=region)
client = boto3.client("rds",region_name=region)
...