Skip to content

Instantly share code, notes, and snippets.

@lloesche
Last active January 10, 2022 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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)'
@AMMullan
Copy link

AMMullan commented Mar 8, 2021

Unfortunately this works for newer regions, but the older EU regions don't work. I've had to have overrides for these:

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)'

Issue was raised with AWS but no plans on fixing it either :/ See boto/botocore#2078

@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