Reject unmapped method request in aws API gateway

0

Hi, I have a lambda running with bunch of APIs. For example consider the below details, Sample API example, PATH: /aws/test/save **METHOD **: POST

My API gateway has the above path with POST method and if I make a API call with POST method the lambda will initialize and the data will be posted into the database.

Problem Statement: If I make same API call with GET method I am getting 405 as expected but it's spinning up the lambda server, which I don't want.

What I am expecting: Is it possible to reject the GET request which is not at all mapped in the API gate for the above path.

**NOTE **: Basically only the mapped Path with assigned method should start the lambda all other unmapped path or method should be rejected and should not start the lambda.

1 Answer
1

How are you determining that the Lambda function is being invoked when a GET is sent to API Gateway?

I've got a test API Gateway here; in my case GET is mapped to a Lambda function and I get an expected value returned and I also see an invocation happening in CloudWatch Logs. But if I send a POST request API Gateway responds with 403.

Are you using specific methods in API Gateway? Or using "ANY"? If "ANY" Then yes, Lambda will be invoked for all methods. But if API Gateway is configured with specific methods anything which is not mapped will not invoke the back-end function (Lambda in this case).

profile pictureAWS
EXPERT
answered a year ago
  • @Brettski-AWS thank you for your explanation. The issue has been resolved now. I had a greedy proxy which was invoking the backend code.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions