Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cold" start of S3, DynamoDB, KMS or whatever

I use NodeJs AWS Lambdas. If I don't do calls to my S3, or DynamoDB, or KMS for some time (approx. 8h or more) the first call I make is usually painfully slow - up-to 5sec. There's nothing complex in the queries themselves - i.e. get a 0.2Kb S3 object, query a DynamoDB table by index.

So, it looks like AWS "hibernates" these resources when they aren't in active use and when I call them for the 1st time after a while they spend some time to return from "hibernated" state. This is my assumption, but I couldn't find any information about it in docs. So, the questions are the following two:

  1. Is my assumption about "hibernation" correct?
  2. If 1st point is correct, then is there any way to mitigate these "cold" calls to AWS services except keeping those services "warm" by calling them every X minutes?

Edit

Just to avoid confusions - this is not about Lambda's cold starts. I'm aware of them, they exist, they have their own share in functions' latency. Times I measure are the exact times of calls to S3/DynamoDB etc. - after the lambda is started.

like image 979
Viktor Molokostov Avatar asked Mar 08 '18 09:03

Viktor Molokostov


1 Answers

It all likelihood it is the lambda function that is hibernating, not the other services:

A cold start occurs when an AWS Lambda function is invoked after not being used for an extended period of time resulting in increased invocation latency.

https://medium.com/@lakshmanLD/resolving-cold-start%EF%B8%8F-in-aws-lambda-804512ca9b61

and yes, you could setup a cloudwatch event to keep your lambda function warm.

like image 167
E.J. Brennan Avatar answered Sep 28 '22 02:09

E.J. Brennan