AWS TCET

Learn/Labs

Labs · 15 min read · August 2026

CloudWatch: Logs, Metrics, and One Alarm That Matters

How AWS documents observability: log groups, namespaces, and alarms — enough to know a Lambda is broken without SSHing anywhere.

Source. Amazon CloudWatch User Guide · Lambda logging

Abstract & theoretical context

CloudWatch is the default telemetry plane: metrics (time series), logs (events), and alarms (thresholds that page you). Lambda writes to /aws/lambda/<function> automatically if the execution role allows logs. Students often “finish” a lab with a 200 in the console and zero alarms. This note follows the official model: emit, query, alarm, then tear down so log storage does not linger.

Models, formulas & variables

  1. 1. Alarm

    IF metric over threshold for N datapoints THEN action (SNS / nothing in a quiet lab)

    • — Errors metric on Lambda is the first alarm worth creating.
    • — Missing data should be treated as breaching for a demo API.
  2. 2. Log identity

    log group /aws/lambda/name + stream ≈ one container instance

    • — Filter patterns find ERROR without downloading the whole stream.
    • — Retention of 3–7 days is enough for campus labs.

Reference implementation

Copy into a sandbox account. Pin Region ap-south-1 unless the lab says otherwise.

put-metric-alarm.sh

AWS CLI · CloudWatch

aws logs describe-log-groups --log-group-name-prefix /aws/lambda/
aws cloudwatch put-metric-alarm \
  --alarm-name tcet-sbg-lambda-errors \
  --metric-name Errors \
  --namespace AWS/Lambda \
  --statistic Sum \
  --period 60 \
  --threshold 1 \
  --comparison-operator GreaterThanOrEqualToThreshold \
  --evaluation-periods 1 \
  --dimensions Name=FunctionName,Value=hello-sbg

Lab procedure

  1. 01Confirm the Lambda execution role has logs:CreateLogGroup, CreateLogStream, PutLogEvents.
  2. 02Invoke the function with a bad payload until it errors.
  3. 03Open the log group and find the stack trace.
  4. 04Create the Errors alarm above. Delete it at the end of the lab.
  5. 05Set log retention so the group is not Never expire.

Key insights

  • No logs usually means IAM, not “CloudWatch is down.”
  • X-Ray is the next module. Do not start there.
  • Alarms without an action still train you to look at the metric.

Account & lab requirements

A Lambda you own in a sandbox. CloudWatch Logs is billed by ingestion and storage.

More in Labs