Last active
July 12, 2019 19:31
-
-
Save allankp/4dd757f483226b292a23c85c5369b502 to your computer and use it in GitHub Desktop.
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
| 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