5

On my AWS Lambda dashboard, I see a spike in failed invocations. I want to investigate these errors by looking at the logs for these invocations. Currently, the only thing I can do to filter these invocations, is get the timeline of the failed invocations, and then look through logs.

Is there a way I can search for failed invocations, i.e. ones that did not return a 200, and get a request ID that I can then lookup in CloudWatch Logs?

keian
  • 307
  • 4
  • 11

2 Answers2

1

You may use AWS X-Ray for this by enabling in AWS Lambda dashboard.

In X-Ray dashboard;

  • you may view traces
  • filter them by status code
  • see all the details of the invocation including request id, total execution time etc such as
{
    "Document": {
        "id": "ept5e8c459d8d017fab",
        "name": "zucker",
        "start_time": 1595364779.526,
        "trace_id": "1-some-trace-id-fa543548b17a44aeb2e62171",
        "end_time": 1595364780.079,
        "http": {
            "response": {
                "status": 200
            }
        },
        "aws": {
            "request_id": "abcdefg-69b5-hijkl-95cc-170e91c66110"
        },
        "origin": "AWS::Lambda",
        "resource_arn": "arn:aws:lambda:eu-west-1:12345678:function:major-tom"
    },
    "Id": "52dc189d8d017fab"
}
Ersoy
  • 8,816
  • 6
  • 34
  • 48
0

What I understand from your question is you are more interested in finding out why your lambda invocation has failed rather than finding the request-id for failed lambda invocation.

You can do this by following the steps below:

  1. Go to your lambda function in the AWS console.
  2. There will be three tabs named as Configuration, Permissions, and Monitoring
  3. Click on the Monitoring Tab. Here you can see the number of invocation, Error count and success rate, and other metrics as well. Click on the Error metrics. You will see that at what time the error in invocation has happened. You can read more at this Lambda function metrics
  4. If you already know the time at which your function has failed then ignore Step 3.
  5. Now scroll down. You will find the section termed as CloudWatch Logs Insights. Here you will see logs for all the invocation that has happened within the specified time range.
  6. Adjust your time range under this section. You can choose a predefined time range like 1h, 3h, 1d, etc, or your custom time range.
  7. Now Click on the Log stream link after the above filter has been applied. It will take you to cloudwatch console and you can see the logs here.
Ajay Kr Choudhary
  • 1,304
  • 1
  • 14
  • 23