Lesson 1 of 3 Monitoring Serverless and AI Workloads

Monitoring Lambda Functions with Metrics, Logs and Lambda Insights

This lesson covers the default telemetry, Lambda Insights and the most useful alarms for Lambda functions, which have no servers to log into.

Learning outcomes

After completing this lesson, you will be able to:

  • Interpret the default Lambda metrics and logs.
  • Describe what Lambda Insights adds.
  • Choose alarms for common Lambda failure modes.
  • Diagnose function timeouts.

Default metrics and logs

Lambda publishes metrics in the AWS/Lambda namespace for every function, version and alias at 1-minute granularity at no charge. Invocations counts calls; Errors counts invocations that ended in a function error; Throttles counts requests rejected because no concurrency was available; Duration measures run time (use p99 for latency-sensitive functions); ConcurrentExecutions shows instances running at once; IteratorAge shows how far behind a stream consumer is; and AsyncEventAge and DeadLetterErrors describe asynchronous processing.

Every invocation writes START, END and REPORT lines plus anything the code prints to the function's log group. The REPORT line gives duration, billed duration, memory size, maximum memory used and init duration for cold starts. The execution role needs logs:CreateLogGroup, logs:CreateLogStream and logs:PutLogEvents, which the AWSLambdaBasicExecutionRole managed policy grants; a function whose role lacks them runs but produces no logs. Advanced logging controls let functions emit JSON logs, set application and system log levels, and write to a custom log group.

Lambda Insights

CloudWatch Lambda Insights adds system-level metrics that the default metrics do not provide: CPU time, memory utilisation, network usage, disk usage in /tmp and cold start counts. It is enabled by adding the Lambda Insights extension layer to the function and the CloudWatchLambdaInsightsExecutionRolePolicy managed policy to its role. Data goes to the /aws/lambda-insights log group as embedded metric format events, and curated multi-function and single-function views appear in the CloudWatch console. Use it when you must decide whether a function needs more memory or is CPU-bound.

Scenario questions

Default metrics or Lambda Insights?

Exam skills 1.1.1 · 1.2.1

Decide when Lambda Insights is needed.

Log in to try this activity Interactive activities are free with an account.

Useful alarms for Lambda

The following table lists alarms that cover the most common Lambda failure modes, with the statistic that makes each one meaningful.

Alarm onStatisticWhat it detects
Errors (or Errors / Invocations with metric math)SumFunction code failures
ThrottlesSumReserved or account concurrency exhausted
Durationp99 or MaximumFunctions approaching their timeout
IteratorAgeMaximumStream processing falling behind (Kinesis, DynamoDB Streams)
ConcurrentExecutions (account level)MaximumApproaching the Regional concurrency quota
DeadLetterErrorsSumFailed deliveries to a dead-letter queue
Match the pairs

Which Lambda metric?

Exam skills 1.1.1 · 1.1.3

Match each concern with the Lambda metric that reveals it.

Log in to try this activity Interactive activities are free with an account.
Worked example

Diagnosing timeouts

A function with a 30-second timeout starts failing. The Errors alarm fires and the log group shows Task timed out after 30.03 seconds. Lambda Insights shows CPU time close to duration, which means the function is CPU-bound rather than waiting on a dependency. Because Lambda allocates CPU in proportion to memory, the operator raises memory from 512 MB to 1,769 MB, where a function receives the equivalent of one full vCPU. Duration falls to 9 seconds and the cost per invocation drops, because the shorter run time outweighs the higher price per millisecond. AWS Compute Optimizer gives the same recommendation automatically for functions with enough history.

Check yourself

A function runs, but no logs appear. What is the most likely cause?

Show answer

Its execution role lacks CloudWatch Logs permissions.

Exam Tips

Remember for the exam

  • Lambda publishes Invocations, Errors, Throttles, Duration and ConcurrentExecutions by default.
  • No logs from a function: its execution role lacks CloudWatch Logs permissions.
  • Lambda Insights adds CPU, memory and cold start metrics through an extension layer.
  • CPU scales with memory; CPU-bound functions often get faster and cheaper with more memory.
  • IteratorAge shows stream consumers falling behind.