How can we calculate the number of Apis exposed through AWS api gateway?

Viewed 53

So We have multiple API gateways and in each gateway, we have exposed multiple RESt endpoints. Is there any way to calculate the number of endpoints exposed in each gateway ?

2 Answers

This python script worked for me:

import boto3
from botocore.exceptions import ClientError
import logging

apiGw = boto3.client("apigateway",region_name = "ap-south-1")

def get_rest_api_id():
    """Retrieve the ID of an API Gateway REST API
    :return: Retrieved API ID. If API not found or error, returns None.
    """

    # Retrieve a batch of APIs
    try:
        apis = apiGw.get_rest_apis()
    except ClientError as e:
        logging.error(e)
        return None

    return apis

apis = get_rest_api_id()["items"]
totalPaths = 0
for api in apis:
    response = apiGw.get_resources(
        restApiId=api["id"]
    )
    items = response["items"]
    pathCount = len(items)
    print(api["name"])
    print ("Total Paths = {}".format(pathCount))
    totalPaths=totalPaths+pathCount

print("Total Paths : {}".format(totalPaths))
Related