How do I use CloudWatch Logs to determine if my Lambda function timed out?

2 minute read
2

My AWS Lambda function experienced intermittent errors and I want to use Amazon CloudWatch Logs to determine if my function timed out.

Resolution

When a Lambda function invocation times out, a Task timed out error message appears in the failed invocation's CloudWatch logs, not an Error message. When you review your Lambda function's CloudWatch log group, search for "Task timed out". If you search the logs only for Error messages, then the search returns only code-related runtime errors, not invocation timeout errors. For more information, see Monitoring AWS Lambda errors using Amazon CloudWatch.

Use the request IDs of the associated timed-out invocations to retrieve the full logs for each invocation timeout.

Before you begin, make sure that your Lambda function has the required AWS Identity and Access Management (IAM) permissions to upload logs to CloudWatch Logs.

Get the request IDs for timed-out invocations

Complete the following steps:

  1. Open the Lambda console.
  2. In the navigation pane, choose Functions.
  3. Select your Lambda function, and then choose the Monitor tab.
  4. Choose View CloudWatch logs to open the function's Log group details page on the CloudWatch console.
  5. Choose View in Logs Insights.
  6. In the Logs Insights query text box, enter the following query, and then choose Run query:
    fields @timestamp, @requestId, @message, @logStream| filter @message like "Task timed out"
    | sort @timestamp desc
    | limit 100

The response returns a list of request IDs in the Task timed out output for the timed-out invocations.

For more information, see Analyzing log data with CloudWatch Logs Insights.

Note: For large log groups, add a datetime function to the Logs Insights query to limit the scope of the search. For more information, see CloudWatch Logs Insights language query syntax.

Run CloudWatch Logs Insights queries for the request IDs

Note: CloudWatch Logs Insights queries incur charges based on the amount of data that you query. For more information, see Amazon CloudWatch pricing.

Use the request IDs of the timed-out invocations to retrieve the full logs for each invocation timeout. You can create a query to search for all logs for the specific request IDs. For more information, see Parsing logs and structured logging.

To troubleshoot any timeout errors that you identify, see How do I troubleshoot Lambda function invocation timeout errors?

AWS OFFICIAL
AWS OFFICIALUpdated a month ago
1 Comment

Can this log be turned off? We seem to have lost it since our lambda executions are timing out without printing it anymore.

Also, there is a new "status: timeout" text in the final RAM used message now. Can that be consumed through some metric or similar instead of grepping logs?

replied 2 months ago