Retrieving the log stack on API Gateway 4XX error 5XX error


When There is an error during an API gateway call I can find thanks to Cloudwatch X-ray the log trace of the error including all the log of api gateway and all the log of the lambda triggered by the call.

I would like to receive of reccord this log every time API gateway return a 4XX or 5XX to be able to invesgate quicker, what is the way to trigger an event with all the required information ?

1 Answer

Enable Execution logs on API Gateway, set it to Errors and add a subscription to the CloudWatch logs group that will notify you.

You can also create an alarm on the 4xx or 5xx metric.

profile pictureAWS
answered 9 months ago
  • Hello, thanks for your answers, the execution logs are indeed enabled and i can read the log on cloudwatch, i also created alarm that inform me when an error is returned but it does give any information that could be use to retrieve the corresponding logs, excepting the time range.

    I guess the cloudwatch subscription to every log could do the tricks if setted to error but It is legal requirement for me to keep all the logs. also it does not return any information about the lambda triggered. in my case i did not find a way to create a filter properly

  • If you need to save all logs, you can send all logs to CWL, create a subscription filer to Lambda. The filter pattern should include the error you are looking for, e.g, "Error 500" (not sure how it actually looks in the log). When the function is invoked it gets in the event the log group and log stream so you can use that to get all the messages from that specific stream. Each log stream correlates with a single API call.

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