Cloud Tech by Victor
DevOpsIntermediate

AWS CloudWatch & CloudTrail

How CloudWatch metrics, logs, and alarms fit together with CloudTrail's audit trail, and why CloudTrail answers "who did what" while CloudWatch answers "what is the system doing."

Updated 2026-07-243 min read

Overview

CloudWatch and CloudTrail answer different questions and are commonly conflated because both involve logging. CloudWatch is the operational-observability platform, metrics, logs, dashboards, and alarms describing what a system is actually doing. CloudTrail is the audit trail of AWS account activity, a record of API calls and console actions describing who did what. Every CloudTrail trail logs management events (control-plane actions) by default, but data events (object- or invocation-level activity on the resources themselves) are opt-in and cost extra, a gap that only tends to surface during an actual investigation that needed them.

Quick Reference

ComponentAnswersLogged by default
CloudWatch MetricsWhat is the system doingYes, emitted automatically by applicable AWS services
CloudWatch AlarmsIs a threshold breachedNo, explicitly created, not present by default
CloudWatch LogsWhat did the application/service emitDepends on whether logging is configured
CloudTrail management eventsWho changed what configuration/control-plane stateYes
CloudTrail data eventsWho read/wrote a specific object or invoked a specific resourceNo, opt-in, additional cost

Syntax

bash
aws cloudwatch put-metric-alarm \
  --alarm-name high-error-rate \
  --comparison-operator GreaterThanThreshold \
  --threshold 0.05 --evaluation-periods 2 \
  --metrics '[
    {"Id": "errors", "MetricStat": {"Metric": {"Namespace": "AWS/Lambda", "MetricName": "Errors", "Dimensions": [{"Name": "FunctionName", "Value": "process-orders"}]}, "Period": 60, "Stat": "Sum"}, "ReturnData": false},
    {"Id": "invocations", "MetricStat": {"Metric": {"Namespace": "AWS/Lambda", "MetricName": "Invocations", "Dimensions": [{"Name": "FunctionName", "Value": "process-orders"}]}, "Period": 60, "Stat": "Sum"}, "ReturnData": false},
    {"Id": "error_rate", "Expression": "errors / invocations", "Label": "ErrorRate", "ReturnData": true}
  ]'

Examples

sql
-- CloudWatch Logs Insights - find the slowest 5% of requests to
-- a specific endpoint in the last hour, something no alarm or
-- pre-built dashboard was set up to answer.
fields @timestamp, @message
| filter @message like /POST \/api\/orders/
| stats pct(duration, 95) as p95 by bin(5m)

CloudTrail data events are opt-in and cost extra

Enabling a trail logs management events by default, creating a role, changing a security group, but not object-level S3 access or individual Lambda invocations. If an investigation needs "who read this exact object," data events have to have been explicitly enabled beforehand, there's no retroactive way to recover that visibility.

Visual Diagram

Common Mistakes

  • Confusing CloudTrail's audit trail with CloudWatch's operational data, expecting CloudTrail to explain a performance problem, or CloudWatch to explain who changed a security group.
  • Assuming CloudTrail captures object-level S3 access or per-invocation Lambda activity out of the box, when only management events are on by default.
  • Alarming only on CPU utilization when the real bottleneck is latency, error rate, or queue depth, custom metrics included.
  • Ingesting high-volume debug-level application logs into CloudWatch Logs with no retention policy, driving up ingestion and storage cost indefinitely.

Performance

  • CloudWatch metric resolution is configurable, standard 1-minute or high-resolution down to 1 second, higher resolution costs more and should be reserved for genuinely latency-sensitive alarms.
  • CloudWatch Logs Insights query cost and speed scale with the volume of log data scanned; a tight time-range filter is the single biggest lever on both.
  • CloudTrail log delivery to S3 has real, non-trivial delivery latency, it is an audit trail for after-the-fact investigation and compliance, not a real-time alerting mechanism.

Best Practices

  • Use CloudTrail for "who did what" (compliance, audit, security investigation) and CloudWatch for "what is the system doing" (operational health); don't expect one to answer the other's questions.
  • Enable CloudTrail data events explicitly for any resource where object- or invocation-level audit genuinely matters, S3 buckets and Lambda functions handling sensitive data are the common case.
  • Alarm on the metric that reflects the real bottleneck, latency, error rate, queue depth, not CPU utilization by default.
  • Set explicit CloudWatch Logs retention policies per log group instead of leaving the default indefinite retention in place.

Interview questions

What is the difference between CloudWatch and CloudTrail?

CloudWatch is the operational observability platform: metrics, logs, dashboards, and alarms that answer "what is the system doing right now," CPU usage, request latency, error rates, application log output. CloudTrail is the audit trail of AWS account activity: a record of API calls and console actions that answers "who did what, when, from where," regardless of whether that action succeeded, failed, or even touched application behavior at all. They are frequently confused because both involve "logs," but CloudWatch Logs holds whatever an application or service chooses to emit, while CloudTrail holds a record of AWS API calls themselves, and neither substitutes for the other.

What is the difference between CloudTrail management events and data events, and why does it matter?

Management events record control-plane operations, creating a role, launching an instance, changing a security group, and every CloudTrail trail logs these by default. Data events record data-plane operations on the resources themselves, an individual S3 GetObject or Lambda Invoke call, and are not logged by default; they have to be explicitly enabled per resource and typically cost extra given their much higher volume. This matters because an investigation into "who read this specific S3 object" will come up completely empty if only the default management events were ever being logged, a genuinely common gap discovered only during an actual incident.

When would you use a CloudWatch alarm versus digging into CloudWatch Logs Insights?

A CloudWatch alarm watches a metric against a threshold and is the right tool for fast, simple, near-real-time detection, error rate crossing 5%, latency crossing a p99 target. CloudWatch Logs Insights is a query language for ad hoc investigation of the underlying log data, the tool for answering a specific question an alarm was never built to ask, like "which requests failed, and what did they have in common." Alarms are for detecting that something is wrong quickly; Logs Insights is for actually finding out why once an alarm (or a user report) says something is.

References

ShareXLinkedInReddit
Was this page helpful?
Suggest an improvement