I need to count the number of methods on AWS API Gateway. I'm very new to python scripting. It doesn't care about any path, and it's just that the OPTIONS method doesn't count. GET, POST, PUT, etc. sections (exclude OPTION)
Here I attach the code that I'm currently trying to implement.
import boto3
Create a client for the API Gateway service
client = boto3.client('apigateway')
Get the ID of the API Gateway
api_id = 'my_api_id'
Get the list of resources in the API Gateway
resources = client.get_resources(restApiId=api_id)
Initialize a variable to store the number of methods
method_count = 0
# Get the list of methods for each resource
for resource in resources['items']:
resource_methods = client.get_methods(restApiId=api_id, resourceId=resource['id'])
for method in resource_methods['items']:
if method['httpMethod'] != 'OPTIONS':
method_count += 1
# Print the number of methods
print(method_count)
I got this error and am still confused about doing the calculations. Please help. Your response is precious.
Traceback (most recent call last):
File "aws_count_endpoint_api-2.py", line 17, in <module>
resource_methods = client.get_methods(restApiId=api_id, resourceId=resource['id'])
File "/home/users/.local/lib/python3.8/site-packages/botocore/client.py", line 646, in __getattr__
raise AttributeError(
AttributeError: 'APIGateway' object has no attribute 'get_methods'