Lambda Insights
CloudWatch Lambda Insights โ an AWS-native way to get detailed metrics and traces for your Lambda functions, including:
-
Memory usage
-
CPU time
-
Invocation count
-
Cold start duration
-
Error and timeout rates
๐ What is Lambda Insights?¶
CloudWatch Lambda Insights provides enhanced telemetry for AWS Lambda functions. It installs an internal Lambda extension that sends additional performance metrics and diagnostics to CloudWatch.
It's different from basic Lambda metrics like invocation count or duration โ this is deeper observability for performance tuning and troubleshooting.
๐งฐ What You'll Get¶
-
Memory usage over time
-
CPU time used
-
Cold starts
-
Errors and timeouts
-
Logs with correlation to invocations
โ Enable Lambda Insights (3 Options)¶
Option 1: Console (Easiest)¶
-
Go to the AWS Console โ Lambda
-
Select your function
-
Choose Monitor โ View in CloudWatch
-
Enable Lambda Insights
Option 2: AWS CLI¶
aws lambda update-function-configuration \
--function-name my-function-name \
--layers arn:aws:lambda:<region>:580247275435:layer:LambdaInsightsExtension:14 \
--tracing-config Mode=Active
Replace
<region>andmy-function-nameaccordingly.
Option 3: Infrastructure as Code (Example with Terraform)¶
resource "aws_lambda_function" "my_lambda" {
function_name = "my_lambda"
handler = "index.handler"
runtime = "nodejs18.x"
role = aws_iam_role.lambda_exec.arn
filename = "function.zip"
layers = [
"arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:14"
]
}
resource "aws_iam_role_policy_attachment" "lambda_insights_attach" {
role = aws_iam_role.lambda_exec.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
}
๐ View Insights in CloudWatch Console¶
-
Go to CloudWatch โ Lambda Insights
-
Select your function
-
Explore:
-
Invocations
-
Cold starts
-
Memory usage
-
CPU time
-
Logs linked to traces
-
๐งช Example Use Case¶
You want to detect whether your Lambda is using too much memory or hitting timeouts.
Step-by-step:¶
-
Enable Lambda Insights
-
Invoke the function a few times
-
Go to CloudWatch โ Lambda Insights โ Performance
-
You'll see a breakdown like:
| Invocation | Duration | Cold Start | Memory Used | CPU Used |
|------------|----------|------------|-------------|----------|
| #1 | 100ms | Yes | 90MB | 25ms |
| #2 | 95ms | No | 70MB | 20ms |
You can use this to:
-
Optimize memory (reduce if underused, increase if out of memory)
-
Understand performance bottlenecks
-
Spot cold start issues
๐ Summary¶
| Feature | Enabled by |
|---|---|
| Memory usage tracking | Lambda Insights |
| CPU time usage | Lambda Insights |
| Cold start detection | Lambda Insights |
| Invocation breakdowns | Lambda Insights |
| Linked logs and traces | Lambda Insights + X-Ray (optional) |