我们如何计算通过 AWS api 网关公开的 API 数量?

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

所以我们有多个 API 网关,在每个网关中,我们公开了多个 RESt 端点。有什么方法可以计算每个网关中暴露的端点数量吗?

这个命令应该可以。

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/

这个 python 脚本对我有用:

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