Lambda randomly times out

0

Hello,

My lambda function randomly times out, and the output logs are weird: Enter image description here

As you can see, the Start and End timestamps are 1706515729145 1706515729767

which are about 600ms apart. However, the logs say the task times out after 5s (which in itself is really surprising, as the lambda does nothing except parse a small string into JSON, and send it to an SQS queue). This happens randomly (maybe once in 10k / 20k invocations).

Any clue as what might be happening here?

Thanks :)

asked 3 months ago178 views
4 Answers
1

Increase the Lambda timeout. It can be configured up to 15 mins. It looks like yours is set to 5 seconds. It may be it just needs a few more seconds for your code to finishing executing

https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-common.html#configuration-timeout-console

profile picture
EXPERT
answered 3 months ago
1

The Coldstart is also included in the total execution time. It may be because your function warms up the first time and on the 2nd run its already started so runs instantly without a cold start.. I believe you can review the warm up time. May also be worth enabling Lambda Insights for more information

I still recommend increasing time out.

profile picture
EXPERT
answered 3 months ago
0

Thanks for your reply! The 5s timeout is totally fine, as the process is usually done in a few hundreds of milliseconds. Even in this case, the time elapsed between start and end of the request is about 600ms and should not have triggered a "timed out" error, which is what I'm worried about here.

answered 3 months ago
0

Thanks for the insight.

According to the docs, "You are not charged for the time it takes for Lambda to prepare the function but it does add latency to the overall invocation duration." (see https://docs.aws.amazon.com/lambda/latest/operatorguide/execution-environments.html). However, the "billed duration" is at 5s, so it can't be caused by the cold start of the function (and a cold start time of 4s would be extremely surprising for such a small NodeJS function).

answered 3 months ago

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