How do I determine if my Lambda function is timing out?
"My AWS Lambda function is experiencing intermittent errors, and it's not clear why when I review the function's Amazon CloudWatch metrics. Could my Lambda function's increased error rate be caused by timeout issues? If so, how do I determine if my Lambda function is timing out?"
"My AWS Lambda function is experiencing intermittent errors, and it's not clear why when I review the function's Amazon CloudWatch metrics. Could my Lambda function's increased error rate be caused by timeout issues? If so, how do I determine if my Lambda function is timing out?Short descriptionWhen reviewing your Lambda function's CloudWatch log group, search for the phrase Task timed out. Then, use the request IDs of the associated timed-out invocations to retrieve the full logs for each invocation timeout.To troubleshoot any timeout errors that you identify, see How do I troubleshoot Lambda function invocation timeout errors?Note: 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. If you search your function's CloudWatch logs for Error messages only, then the search returns only code-related runtime errors, not invocation timeout errors. For more information, see Monitoring AWS Lambda errors using Amazon CloudWatch.ResolutionPrerequisitesIf you haven't done so already, grant CloudWatch logging permissions to your Lambda function. For more information, see AWS managed policies for Lambda features .Retrieve the request IDs of any timed-out invocations by searching the function's CloudWatch log group for the phrase "Task timed out"Note: CloudWatch Logs Insights queries incur charges based on the amount of data that's queried. For more information, see Amazon CloudWatch pricing.1.    Open the Functions page of the Lambda console.2.    Choose a function.3.    Choose Monitor.4.    Choose View logs in CloudWatch. The function's Log group details page opens in 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 100The response returns a list of request IDs for the timed-out invocations.For more information, see Analyzing log data with CloudWatch Logs Insights.Note: For large log groups, consider limiting the scope of the search by adding a datetime function to the Insights query. For more information, see CloudWatch Logs Insights query syntax.Use the request IDs of the timed-out invocations to retrieve the full logs for each invocation timeoutOutput logs using the standard logging functionality for the programming language that you're using. For language-specific instructions, see the Using the AWS CLI section of Accessing Amazon CloudWatch Logs for AWS Lambda.Follow"