Created
October 19, 2021 14:13
-
-
Save brevityinmotion/a2ff384ebb06fcbe66c85c6096f410a5 to your computer and use it in GitHub Desktop.
Python script to enumerate the short codes and long names for AWS services
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
# Description: Enumerates short codes and long names for AWS services | |
# Code modified from https://www.sentiatechblog.com/retrieving-all-region-codes-and-names-with-boto3 | |
class Services: | |
@classmethod | |
def get_services(cls): | |
short_codes = cls._get_service_short_codes() | |
services = [{ | |
'name': cls._get_service_long_name(sc), | |
'code': sc | |
} for sc in short_codes] | |
services_sorted = sorted( | |
services, | |
key=lambda k: k['name'] | |
) | |
return services_sorted | |
@classmethod | |
def _get_service_long_name(cls, short_code): | |
param_name = ( | |
'/aws/service/global-infrastructure/services/' | |
f'{short_code}/longName' | |
) | |
response = ssm.get_parameters( | |
Names=[param_name] | |
) | |
return response['Parameters'][0]['Value'] | |
@classmethod | |
def _get_service_short_codes(cls): | |
output = set() | |
for page in ssm.get_paginator('get_parameters_by_path').paginate( | |
Path='/aws/service/global-infrastructure/services' | |
): | |
output.update(p['Value'] for p in page['Parameters']) | |
return output | |
# Retrieve service names and short codes | |
for service in Services.get_services(): | |
print(service) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment