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\'
This is the solution I arrived at, which shows all the AWS/EC2 region IDs and names:
$ cat so_regions2.py
import boto3
region = "us-east-1"
print("Using region:", region)
ec2 = boto3.client("ec2", region_name=region)
ec2_responses = ec2.describe_regions()
ssm_client = boto3.client('ssm', region_name=region)
for resp in ec2_responses['Regions']:
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: eu-north-1 region_name: EU (Stockholm)
region_id: ap-south-1 region_name: Asia Pacific (Mumbai)
region_id: eu-west-3 region_name: EU (Paris)
region_id: eu-west-2 region_name: EU (London)
region_id: eu-west-1 region_name: EU (Ireland)
region_id: ap-northeast-2 region_name: Asia Pacific (Seoul)
region_id: ap-northeast-1 region_name: Asia Pacific (Tokyo)
region_id: sa-east-1 region_name: South America (Sao Paulo)
region_id: ca-central-1 region_name: Canada (Central)
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: us-east-1 region_name: US East (N. Virginia)
region_id: us-east-2 region_name: US East (Ohio)
region_id: us-west-1 region_name: US West (N. California)
region_id: us-west-2 region_name: US West (Oregon)
$