Skip to content

Instantly share code, notes, and snippets.

@lloesche
Last active January 10, 2022 22:14
Show Gist options
  • Save lloesche/e73162a3c64116a1b5247c10be169a4e to your computer and use it in GitHub Desktop.
Save lloesche/e73162a3c64116a1b5247c10be169a4e to your computer and use it in GitHub Desktop.
boto short to long region names for use with AWS pricing API
# Get the long region names used by the AWS Pricing API
#
# There's currently no proper API to do this
#
# Example:
# print(SHORT_TO_LONG_REGIONS['us-west-2'])
# > US West (Oregon)
from pkg_resources import resource_filename
endpoints_file = resource_filename('botocore', 'data/endpoints.json')
with open(endpoints_file, 'r') as f:
endpoints = json.load(f)
SHORT_TO_LONG_REGIONS = {k: v['description'] for k, v in next(iter(endpoints.get('partitions', [])), {}).get('regions', {}).items()}
SHORT_TO_LONG_REGIONS['eu-west-1'] = 'EU (Ireland)'
SHORT_TO_LONG_REGIONS['eu-central-1'] = 'EU (Frankfurt)'
SHORT_TO_LONG_REGIONS['eu-north-1'] = 'EU (Stockholm)'
SHORT_TO_LONG_REGIONS['eu-west-2'] = 'EU (London)'
SHORT_TO_LONG_REGIONS['eu-west-3'] = 'EU (Paris)'
@lloesche
Copy link
Author

lloesche commented Mar 8, 2021

Thank you for the heads up! I updated the Gist with your workaround. The discussion in that botocore issue is just sad to read 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment