Last active
February 24, 2022 15:28
-
-
Save mariocesar/052a34d2c357cc084bd243bd5bbb44da to your computer and use it in GitHub Desktop.
Get all available regions supported by boto library for an AWS service, like S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from botocore.loaders import create_loader | |
from botocore.regions import EndpointResolver | |
endpoints = create_loader().load_data('endpoints') | |
partitions = [part['partition'] for part in endpoints['partitions']] | |
for partition in partitions: | |
s3_regions = EndpointResolver(endpoints).get_available_endpoints("s3", partition) | |
aws_partition = next( | |
filter(lambda part: part["partition"] == partition, endpoints['partitions']) | |
) | |
print(f"Partition: {partition}") | |
for region in s3_regions: | |
print(" -", aws_partition["regions"][region]["description"], region) | |
print() | |
""" | |
Partition: aws | |
- Africa (Cape Town) af-south-1 | |
- Asia Pacific (Hong Kong) ap-east-1 | |
- Asia Pacific (Tokyo) ap-northeast-1 | |
- Asia Pacific (Seoul) ap-northeast-2 | |
- Asia Pacific (Mumbai) ap-south-1 | |
- Asia Pacific (Singapore) ap-southeast-1 | |
- Asia Pacific (Sydney) ap-southeast-2 | |
- Canada (Central) ca-central-1 | |
- Europe (Frankfurt) eu-central-1 | |
- Europe (Stockholm) eu-north-1 | |
- Europe (Milan) eu-south-1 | |
- Europe (Ireland) eu-west-1 | |
- Europe (London) eu-west-2 | |
- Europe (Paris) eu-west-3 | |
- Middle East (Bahrain) me-south-1 | |
- South America (Sao Paulo) sa-east-1 | |
- US East (N. Virginia) us-east-1 | |
- US East (Ohio) us-east-2 | |
- US West (N. California) us-west-1 | |
- US West (Oregon) us-west-2 | |
Partition: aws-cn | |
- China (Beijing) cn-north-1 | |
- China (Ningxia) cn-northwest-1 | |
Partition: aws-us-gov | |
- AWS GovCloud (US-East) us-gov-east-1 | |
- AWS GovCloud (US-West) us-gov-west-1 | |
Partition: aws-iso | |
- US ISO East us-iso-east-1 | |
Partition: aws-iso-b | |
- US ISOB East (Ohio) us-isob-east-1 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment