[英]Can we delete a API in AWS API Gateway? If yes then how?
[英]How can we calculate the number of Apis exposed through AWS api gateway?
所以我们有多个 API 网关,在每个网关中,我们暴露了多个 REST 端点。 有没有办法计算每个网关中暴露的端点数量?
这个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))
这个命令应该可以。
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/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.