Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get notifications when AWS Lambda timesout

Is there a way to get notifications when my AWS Lambda function times out?

I am unable to find any documentation. The only way as of now is to search through the Cloudwatch logs for timeout notifications of all the Lambda functions I have. Is there a better way?

like image 755
Chenna V Avatar asked Feb 22 '16 21:02

Chenna V


People also ask

What happens when AWS Lambda timeout?

When the specified timeout is reached, AWS Lambda terminates execution of your Lambda function. As a best practice, you should set the timeout value based on your expected execution time to prevent your function from running longer than intended. This feature is available in all regions where AWS Lambda is available.

How do you deal with Lambda timeout?

Verify that the retry count and timeout settings on the AWS SDK that you're using allow enough time for your function to initialize. Increase the Lambda function's timeout setting temporarily to allow enough time for the function code to generate log data.


2 Answers

I've created an alarm in CloudWatch for a Lambda metric of type "Duration" and selected the Statistic of "Maximum" to alert me when the execution duration is greater/equal 30000 (= 30 seconds) for a Lambda function configured with a timeout of 30 seconds.

If the duration of a single execution ("maximum" of the period) exceeds the timeout time, you will be notified. It is working fine for me.

like image 175
Zanon Avatar answered Sep 21 '22 15:09

Zanon


According to the docs, a timeout should be in the Errors metric. I observed weird behaviour with the count (e.g. having an error count of 0.5). Hence I made a CloudWatch alarm for the errors count > 0 (not >= 1).

You could also do something with the REPORT message or with

Task timed out after 25.00 seconds

which can be found in the Cloudwatch logs.

like image 38
Martin Thoma Avatar answered Sep 23 '22 15:09

Martin Thoma