A simple way to get AWS Service Quotas using Python
Last active
August 9, 2023 12:50
-
-
Save nicc777/34531415f9b3d24a9aeddc74fa64e3dc to your computer and use it in GitHub Desktop.
AWS Service Quotas
This file contains 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
import boto3 | |
import json | |
def get_services(client, next_token: str=None)->list: | |
response = dict() | |
data = list() | |
if next_token is not None: | |
response = client.list_services(NextToken=next_token) | |
else: | |
response = client.list_services() | |
if 'NextToken' in response: | |
if isinstance(response['NextToken'], str): | |
if len(response['NextToken']) > 0: | |
data += get_services(client=client, next_token=response['NextToken']) | |
if 'Services' in response: | |
for service_data in response['Services']: | |
data.append(service_data) | |
return data | |
json.dumps(get_services(client=client), default=str) |
This file contains 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
import boto3 | |
import json | |
client = boto3.client('service-quotas') | |
def get_service_quotas(client, service_code: str, quota_name_matched: list=list(), next_token: str=None)->list: | |
response = dict() | |
data = list() | |
if next_token is not None: | |
response = client.list_service_quotas(ServiceCode=service_code,NextToken=next_token) | |
else: | |
response = client.list_service_quotas(ServiceCode=service_code) | |
if 'NextToken' in response: | |
if isinstance(response['NextToken'], str): | |
if len(response['NextToken']) > 0: | |
data += get_service_quotas(client=client, service_code=service_code, quota_name_matched=quota_name_matched, next_token=response['NextToken']) | |
if 'Quotas' in response: | |
for service_data in response['Quotas']: | |
if len(quota_name_matched) == 0: | |
data.append(service_data) | |
else: | |
if 'QuotaName' in service_data: | |
for qn in quota_name_matched: | |
if qn in service_data['QuotaName']: | |
data.append(service_data) | |
return data | |
# The service code is something you get from the script get_service_codes.py | |
json.dumps(get_service_quotas(client=client, service_code='fsx', quota_name_matched=['OpenZFS', 'ONTAP',]), default=str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment