Eduardo Nascimento
Eduardo Nascimento

Reputation: 31

Log requests on inexistent resources on API Gateway

How can I see requests made to a non created endpoint, provided by AWS API Gateway? I.E: On my API gateway I had only the /customers resource (visible on cloudwatch). But for some reason I want to know if users are making requests to any other endpoint.

Upvotes: 1

Views: 209

Answers (3)

Justin Kruse
Justin Kruse

Reputation: 1130

You could do something like this:

no-endpoint:
  description: catch all non-existent enpoints with 404 - must be last 
  http
  handler: src/functions/api-controller.noEndpoint
  events:
  - http:
      path: /{proxy+}
      method: any
      cors: true

then in the noEndpoint handler log out to CloudWatch logs or whatever logging service you would like to use.

NOTE: this must be the last http function in your template, otherwise it will catch ALL http requests.

proxy+ docs: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html

Upvotes: 0

Piyush Ahuja
Piyush Ahuja

Reputation: 141

Please refer to this thread. https://forums.aws.amazon.com/thread.jspa?messageID=805138#805138

" Unfortunately, API Gateway doesn't provide access logs for the customer. I will create a feature request on API Gateway side, and API Gateway will consider prioritizing this request, but I cannot provide the ETA for this. As the workaround, you can create a proxy resource with a mock integration at the same level as your other resources, and you will be able to see the logs of the requests that are hitting the wrong resources. "

Thanks!

Upvotes: 1

Related Questions