Skip to content

Instantly share code, notes, and snippets.

@perpil
Last active September 6, 2025 16:34
Show Gist options
  • Select an option

  • Save perpil/abfba2feedad54def6698583baed9393 to your computer and use it in GitHub Desktop.

Select an option

Save perpil/abfba2feedad54def6698583baed9393 to your computer and use it in GitHub Desktop.
Cloudwatch Logs Insights Query to get coldstart stats by lambda runtime
filter @message like /INIT_START|REPORT|START/ |
parse @message /INIT_START Runtime Version: (?<runtime>\S+)/ |
parse @message /^START RequestId: .* Version: (?<version>\S+)/ |
stats sortslast(runtime) as `lambda runtime version`, sortslast(@initDuration) as iD, sortslast(version) as `software version` by @logStream |
filter ispresent(`software version`) |
stats pct(iD, 50) as p50, pct(iD, 90) as p90, pct(iD, 95) as p95, pct(iD, 99) as p99 by `lambda runtime version`, `software version`
@perpil
Copy link
Author

perpil commented Apr 13, 2025

Add V1 here that only gets coldstart stats by lambda runtime

filter @message like /INIT_START|REPORT/ |
parse @message /Runtime Version: (?<runtime>\S+)/ |
stats sortslast(runtime) as rt, sortslast(@initDuration) as iD by @logStream | 
stats pct(iD, 50) as p50, pct(iD, 90) as p90, pct(iD, 95) as p95, pct(iD, 99) as p99 by rt

@perpil
Copy link
Author

perpil commented Apr 13, 2025

Output looks like this:
image

@perpil
Copy link
Author

perpil commented Sep 6, 2025

This one shows coldstart time by lambda runtime and memory:

filter @message like /INIT_START|REPORT/ |
parse @message /Runtime Version: (?<runtime>\S+)/ |
parse @message /Memory Size: (?<memorysize>\S+)/ |
stats sortslast(runtime) as rt, sortslast(memorysize) as mem, sortslast(@initDuration) as iD by @logStream| 
filter mem > 0 | #filter logs that are missing REPORT
stats min(iD) as `min`, pct(iD, 50) as p50, pct(iD, 90) as p90, pct(iD, 95) as p95, pct(iD, 99) as p99, pct(iD, 100) as p100, count(*) by rt, mem |
order by p50

Example:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment