Skip to content

Instantly share code, notes, and snippets.

@allankp
Last active July 12, 2019 19:31
Show Gist options
  • Save allankp/4dd757f483226b292a23c85c5369b502 to your computer and use it in GitHub Desktop.
Save allankp/4dd757f483226b292a23c85c5369b502 to your computer and use it in GitHub Desktop.
import boto3
CLIENT = boto3.client("apigateway" , region_name="eu-west-2")
def get_api_resource_ids(api_gateway_id: str) -> dict:
resource_ids = {}
for resource in CLIENT.get_resources(restApiId=api_gateway_id)["items"]:
try:
resource_ids[resource["pathPart"]] = resource["id"]
except KeyError:
pass # Ignore resources with no pathPart
return resource_ids
def get_resource_ids(api_gateway_name: str) -> dict:
api_gateways = CLIENT.get_rest_apis()["items"]
for api_gateway in api_gateways:
if api_gateway["name"] == api_gateway_name:
return get_api_resource_ids(api_gateway["id"])
raise ValueError(f"{api_name} not found.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment