Skip to content

Instantly share code, notes, and snippets.

@tkburns
Last active March 10, 2022 03:54
Show Gist options
  • Save tkburns/0e17a5446695ef0250a9d4ffe77b2598 to your computer and use it in GitHub Desktop.
Save tkburns/0e17a5446695ef0250a9d4ffe77b2598 to your computer and use it in GitHub Desktop.
Assorted queries for AWS CloudWatch Insights

CloudWatch Insights Queries

Assorted queries for AWS CloudWatch Insights

# profile lambda memory usage
filter @type = "REPORT"
| fields
@requestId,
@timestamp,
@billedDuration,
@memorySize / 1024 / 1024 as provisonedMemoryMB,
@maxMemoryUsed / 1024 / 1024 as memoryUsedMB,
memoryUsedMB / provisonedMemoryMB * 100 as memoryUtilizationPercent,
provisonedMemoryMB - memoryUsedMB as overProvisionedMB
| sort by memoryUtilizationPercent desc
# groups invocation cost by lambda name & provisioned memory
# makes it easy to compare costs after tweaking a lambda's provisioned memory
filter @type = "REPORT"
| fields
substr(@log, 25) as name,
@billedDuration,
@memorySize / 1024 / 1024 as provisonedMemoryMB,
@billedDuration * provisonedMemoryMB / 1000 as cost
| stats
avg(@billedDuration) as avgDuration,
avg(cost) as avgCost
by
name,
provisonedMemoryMB
| sort by avgCost desc
#| sort by avgDuration desc
#| sort by provisonedMemoryMB, avgDuration desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment