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

Time:05-25

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 ?

CodePudding user response:

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))

CodePudding user response:

This command should do.

aws apigateway get-rest-apis --no-paginate | jq -r '.items | length'

https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-rest-apis.html https://stedolan.github.io/jq/

  • Related