CloudWatch & Observability

Monitoring and auditing on AWS — CloudWatch metrics, dimensions and resolution, alarms and composite alarms, dashboards, CloudWatch Logs and Logs Insights queries, Embedded Metric Format, X-Ray and OpenTelemetry tracing, Application Signals and SLOs, synthetic canaries, CloudTrail for auditing, AWS Config, and what to alarm on.

Intermediate 6 min readLesson 16 of 19 Interview Q&A

You can't operate what you can't see. On AWS, CloudWatch collects metrics and logs, X-Ray and OpenTelemetry trace requests, and CloudTrail records who did what. The concepts — metrics, logs, traces, SLOs — are covered in Observability and Monitoring and SRE; this is the AWS toolkit.

Metrics

Most AWS services publish metrics automatically: CPUUtilization for EC2, Invocations, Errors, Duration and Throttles for Lambda, HTTPCode_Target_5XX_Count and TargetResponseTime for ALB, ApproximateAgeOfOldestMessage for SQS.

  • A metric lives in a namespace (AWS/Lambda) and is identified by dimensions (FunctionName=create-order).
  • Statistics: Average, Sum, Minimum, Maximum, SampleCount and percentiles (p50, p99) — use percentiles for latency; averages hide the slow tail (Latency and throughput).
  • Resolution: standard 1-minute (EC2 basic monitoring is 5-minute; enable detailed monitoring for 1-minute), or high-resolution down to 1 second for custom metrics.
  • Memory and disk usage on EC2 are not visible to the hypervisor — install the CloudWatch agent to publish them.
  • Metric math combines series (error rate = errors / requests × 100); anomaly detection learns expected bands.

Custom metrics

The cheapest way to publish business and application metrics is the Embedded Metric Format: write a structured log line and CloudWatch extracts the metric asynchronously — no API calls in the request path.

JSON
{
  "_aws": {
    "Timestamp": 1764835200000,
    "CloudWatchMetrics": [{
      "Namespace": "Shop/Orders",
      "Dimensions": [["Service", "PaymentMethod"]],
      "Metrics": [{ "Name": "OrderValue", "Unit": "None" }, { "Name": "CheckoutLatency", "Unit": "Milliseconds" }]
    }]
  },
  "Service": "checkout", "PaymentMethod": "UPI",
  "OrderValue": 1499, "CheckoutLatency": 182, "orderId": "1043"
}

Beware high-cardinality dimensions (user IDs, order IDs): every unique combination is a separate billed metric. Keep those as log fields instead (like orderId above).

Alarms

An alarm watches a metric (or metric-math expression) and changes state — OK, ALARM, INSUFFICIENT_DATA — when it breaches a threshold for N of M evaluation periods. Actions: notify through SNS (to PagerDuty, Slack, email), scale an Auto Scaling group, recover or reboot an EC2 instance, or trigger a rollback in CodeDeploy or CloudFormation.

Alarm: checkout-5xx-rate
  Expression: 100 * HTTPCode_Target_5XX_Count / RequestCount   (ALB, per minute)
  Threshold:  > 1   for 3 of 5 datapoints
  Missing data: notBreaching
  Action:     SNS → on-call
  • Composite alarms combine alarms with AND/OR logic to reduce noise — page only if the error rate and the latency alarm fire, or suppress child alarms during a known incident.
  • Alarm on symptoms users feel (error rate, latency, queue age, failed checkouts), not every cause; send cause-level alarms (CPU, disk) to tickets rather than pages.
  • Decide how to treat missing data: a Lambda with no traffic emits no Errors datapoints.

Logs

CloudWatch Logs organises log events into log groups (per application or function) and log streams (per instance, container or execution environment). Lambda, ECS (awslogs driver), API Gateway, VPC Flow Logs and many other services write there.

  • Set retention on every log group — the default is to keep logs forever, which quietly becomes expensive.
  • Log structured JSON with request IDs and trace IDs so logs can be queried and correlated.
  • Subscription filters stream logs to Lambda, Kinesis/Firehose or OpenSearch; export to S3 for long-term, cheap storage.
  • Metric filters turn log patterns into metrics (count "level":"ERROR").
  • Infrequent Access log class for logs you rarely query.

Logs Insights

A query language for searching and aggregating logs across groups:

fields @timestamp, @message, requestId, latencyMs
| filter level = "ERROR" and service = "checkout"
| stats count(*) as errors by bin(5m), errorCode
| sort errors desc
| limit 20
filter @type = "REPORT"
| stats avg(@duration), pct(@duration, 99), max(@maxMemoryUsed / 1000 / 1000) as maxMemMB by bin(1h)

The second query uses the REPORT line Lambda writes after every invocation to show duration percentiles and peak memory — handy for right-sizing (Lambda).

Traces

In a distributed system a slow request might be slow anywhere. Distributed tracing follows one request across services as a tree of spans.

  • AWS X-Ray and the AWS Distro for OpenTelemetry (ADOT) instrument code and AWS SDK calls; API Gateway, Lambda, Step Functions, ECS and EKS propagate trace context.
  • The trace map shows services and their error and latency rates; individual traces show where the time went.
  • CloudWatch Application Signals builds service-level dashboards (requests, latency, faults) from OpenTelemetry data and lets you define SLOs with error-budget tracking.
  • Sample traces (e.g. 5%, plus all errors) to control cost.

Synthetic and real-user monitoring

  • CloudWatch Synthetics canaries: scripted checks (Node or Python, with headless browsers) that hit your endpoints and user journeys every minute from outside — you find out before customers do.
  • CloudWatch RUM: real-user performance and errors from browsers (Web performance).

Auditing: CloudTrail and Config

CloudTrail records API activity — who (principal), what (action), when, from where (IP), and on which resource — for almost every AWS service.

  • Management events (create, delete, modify resources) are logged by default for 90 days in Event history.
  • Create a trail (an organisation trail across all accounts) to keep logs in a central, locked-down S3 bucket with log file validation; optionally log data events (S3 object reads, Lambda invokes) for sensitive resources.
  • CloudTrail Lake lets you query events with SQL. Feed findings into incident response: "who deleted this security group?"

AWS Config records the configuration history of resources and evaluates them against rules ("all EBS volumes encrypted", "no security group open to 0.0.0.0/0 on port 22"), with optional automatic remediation — continuous compliance (Security on AWS).

What to monitor: a starter set

ComponentKey signals
ALB / API GatewayRequest count, 5xx rate, 4xx rate, p99 latency, unhealthy hosts
LambdaErrors, throttles, p99 duration vs timeout, concurrency, iterator age for streams
ECS / EC2CPU and memory utilisation, running task count vs desired, restarts
SQSAge of oldest message, visible messages, DLQ depth (alarm on > 0)
RDS / AuroraCPU, freeable memory, connections, read/write latency, replica lag, free storage
DynamoDBThrottled requests, system errors, consumed vs provisioned capacity
BusinessOrders per minute, payment success rate, sign-ups — often the first sign something is broken
Interview questions
QWhy can't you see memory utilisation for EC2 in CloudWatch by default?easy

CloudWatch's default EC2 metrics are collected by the hypervisor, which can see CPU, network and disk I/O at the virtual machine boundary but not how the guest operating system uses its memory or file-system space. To get memory and disk utilisation, install the CloudWatch agent inside the instance to publish them as custom metrics.

QWhat's the difference between CloudWatch and CloudTrail?easy

CloudWatch is for operational monitoring: metrics, logs, alarms, dashboards — how your systems are performing. CloudTrail is for auditing: a record of API calls made in your account — who did what, when and from where. You'd use CloudWatch to find out the error rate spiked, and CloudTrail to find out that someone modified the security group just before it.

QHow would you set up alerting for a new service without causing alert fatigue?medium

Define SLOs on user-facing symptoms — availability (non-5xx ratio) and p99 latency — and page on fast burn of the error budget rather than on every blip. Use N-of-M evaluation periods, composite alarms to combine related conditions, and route cause-level signals such as CPU or disk to dashboards or tickets rather than pages. Make every paging alarm actionable with a linked runbook, review alerts after incidents, and delete ones nobody acts on.

Key takeaways
  • CloudWatch metrics are namespaced and dimensioned; use percentiles for latency and the agent for EC2 memory and disk.
  • Publish custom metrics cheaply with Embedded Metric Format; avoid high-cardinality dimensions.
  • Alarms on user-facing symptoms with N-of-M evaluation and composite alarms reduce noise.
  • Set log retention, log structured JSON with request and trace IDs, and query with Logs Insights.
  • Trace requests with X-Ray or OpenTelemetry; define SLOs with Application Signals; probe from outside with Synthetics.
  • CloudTrail audits API activity; AWS Config tracks configuration and compliance.