Is it possible to get an overview of AWS Lambda cold starts, i.e. how many there were and how long they took?
I know there are solutions for cold starts, and I know I could log something on a cold start, but that is not what I need. I want an overview of cold starts in the past.
I know that a new log stream is created when a cold start occurs, so I though I'd use CloudWatch Insights to get the first record of type REPORT
for every log stream. But I can't manage to write a query that would group the reports by log stream and then take the first for every group.
This would give me an overview that I might be able to analyze in Excel, but the data is just too large for Excel:
filter @type = "REPORT"
| fields @logStream, @duration, @timestamp
| sort @logStream, @timestamp asc
I can get the stats max(@duration) by @logStream
but that's not what I want. I want the first record and the take the @duration
from there. Is this at all possible? Or should I be looking elsewhere?
Not sure when it was added, but CloudWatch Logs now details the duration of the cold-start in the Init Duration
field: "For the first request served, the amount of time it took the runtime to load the function and run code outside of the handler method." If Init Duration
isn't included, no cold-start was triggered, and your invocation was handled by an instance that was initialized / running earlier.
Here's the documentation on that for the Node.js runtime.