User-8017771
User-8017771

Reputation: 1612

Lambda function returns timeout even after getting the response

We have a java based AWS lambda function which gets called through API Gateway about 10-15 times a day which is very less as per me.

The Lambda config has a memory of 1024 MB and timeout limit of 15 sec. But from the past week or so, the lambda function times out even after getting the response. And this occurrence is not uniform. It's sporadic. And eventually executes normally after some time.

We have tried optimizing the code and it shouldn't take more than ~8 sec to execute. Hoping to find a solution for this. Let me know if more info is needed.

Thanks in advance.

The issue is similar to this question: AWS Lambda function timing out

The only difference being the tech used: The above question used nodeJS and we use Java

--Update: One more thing I have noticed is when the API is hit after being idle for long, it takes more time to get executed than when you hit it consecutively. I checked the logs and when I hit it for the 1st time it took roughly 7-8 secs to execute and just after 2 consecutive hits the response time reduced to a mere 2 secs.. Very strange...

Upvotes: 2

Views: 1848

Answers (1)

dege
dege

Reputation: 2954

You seem to be having problems related to warmup on the lambda/api gateway. There were already some of people complaining about this.

There are some workarounds you could do to keep the lambda warm, for example triggers.

I checked the logs and when I hit it for the 1st time it took roughly 7-8 secs to execute and just after 2 consecutive hits the response time reduced to a mere 2 secs.. Very strange...

This is because you have a warm lambda, therefore it doesn't need to create a new one.

Upvotes: 1

Related Questions