how to count the number of methods other than OPTION on AWS API Gateway with python

0 votes

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'

Feb 14, 2023 in AWS by Ashwini
• 5,430 points
226 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

How to add SSL certificate to AWS EC2 with the help of new AWS Certificate Manager service

refer this link  https://aws.amazon.com/certificate-manager/faqs/ You can't install the certificates ...READ MORE

answered Jul 19, 2018 in AWS by Priyaj
• 58,090 points
1,598 views
0 votes
1 answer

How can I just increase the size of my root disk on AWS EC2 for use with Elastic Beanstalk?

This can be done using the following ...READ MORE

answered Nov 12, 2018 in AWS by Archana
• 5,640 points
2,939 views
0 votes
1 answer

How to add SSL certificate to AWS EC2 with the help of new AWS Certificate Manager service

You can't install the certificates created by ...READ MORE

answered Feb 21, 2022 in AWS by Korak
• 5,820 points
537 views
0 votes
1 answer
0 votes
1 answer

how to access AWS S3 from Lambda in VPC

With boto3, the S3 urls are virtual by default, ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 58,090 points
9,618 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP