Calculate Average Lambda Cold Start Times

Lambda Cold Starts

So you have a question — how do I calculate the average time Lambda executions are spending in a Cold Start. There’s actually a pretty simple way to calculate this, with the help of CloudWatch Insights.

First its good to know of a valuable field that is provided to you when running queries — the @initDuration field.

So how do we get the average cold start time? We can write a query that will help us not only get the average cold start times, but also the maximum and minimum cold start times.

filter @type = “REPORT”
 | stats max(@initDuration) as maxInit,
     min(@initDuration) as minInit,
     avg(@initDuration) as avgInit

Running this would produce something similar to:

Field     Value
-------------------
avgInit   154.9414
maxInit   173.5
minInit   141.05

If you would like to limit this to a specific timeframe, then modify the time period filter that’s built into the CloudWatch Insights tool bar.

Nadetastic