Monitoring and Auditing

CloudWatch for performance, CloudTrail for who-did-what, Config for resource state, and Trusted Advisor for advice.

What is it?

Four services answer four different questions:

  • Amazon CloudWatch: How is it performing? Collects metrics (CPU, request counts), logs and events. Build dashboards and alarms that notify or trigger actions such as Auto Scaling.
  • AWS CloudTrail: Who did what, when? Records API calls and console actions (management events, optionally data events) for auditing and investigation. CloudTrail Insights flags unusual activity.
  • AWS Config: What is my configuration, and did it change? Records resource configurations over time and checks them against rules (for example 'all volumes must be encrypted').
  • AWS Trusted Advisor: What could I improve? Checks your account against best practices in six categories: cost optimization, performance, security, fault tolerance, service limits and operational excellence. How many checks you get depends on your support plan.

Related services: AWS Health (notices about AWS events that affect you), X-Ray (tracing requests across services) and Systems Manager (operational management of fleets).

Exam trio to never mix up: CloudTrail = who did what (API calls). CloudWatch = how it is running (metrics, logs, alarms). X-Ray = where a request slowed down or failed across distributed services.

CloudTrail in more depth

  • Records API activity from the console, CLI and SDKs. Each event shows who (identity and user agent), when (event time), where (source IP) and what (Region, resource, action).
  • On by default: Event history shows the last 90 days of management events at no charge. For longer retention, create a trail that delivers logs to an S3 bucket, then query them with Amazon Athena (or use CloudTrail Lake).
  • Management events are logged by default. Data events (such as S3 object-level reads and writes, or Lambda invocations) and CloudTrail Insights (unusual API activity) are optional and cost extra.
  • Best practice: turn on log file integrity validation and encryption, send logs to a separate locked-down logging account, and use an organization trail covering all accounts and Regions.

CloudWatch is an umbrella of features:

  • Metrics: time-ordered data points in per-service namespaces (for EC2: CPUUtilization, DiskReadOps, NetworkIn/Out). Memory and disk-space usage inside an instance need the CloudWatch agent.
  • Logs: log events belong to a log stream (one source, such as one instance or one Lambda execution environment); streams belong to a log group. Lambda, RDS and Glue send logs automatically; EC2 needs the agent. Logs Insights runs interactive queries across log groups in its own query language, with sample and saved queries.
  • Alarms: watch a metric against a threshold over several evaluation periods. States: OK, ALARM and INSUFFICIENT_DATA. Actions can notify via SNS, trigger Auto Scaling, or stop/reboot/recover an EC2 instance. A billing alarm is a classic first alarm.
  • Dashboards: shared visual views of metrics.
  • Events became Amazon EventBridge (formerly CloudWatch Events): rules fire targets on event patterns or a schedule, for example 'snapshot this server every hour'.

SLAs, SLIs and SLOs

  • SLI (indicator): what you measure, such as availability, latency, throughput, error rate or durability.
  • SLO (objective): the target for an SLI over a period, for example 99.99% ('four nines') monthly availability.
  • SLA (agreement): a formal promise from provider to customer. If AWS misses it (and you met your side), you get service credits, which grow as monthly uptime drops.
  • AWS SLAs are per service and differ. For example, DynamoDB promises more for global tables than single-Region tables, the Compute SLA covers EC2, EBS, ECS, EKS and others, and the RDS SLA applies to Multi-AZ deployments. There is no single SLA page; look up '<service> SLA'.

AWS Health Dashboard has two views:

  • Service health (public): status of every AWS service by Region.
  • Account health (formerly the Personal Health Dashboard): events, scheduled maintenance and guidance for your resources.

It is free for all customers, and its events can drive alerts through EventBridge.

Explain like I'm 10

CloudWatch is a car's dashboard: speed, fuel, warning lights. CloudTrail is its black-box recorder: every door opened and button pressed, with the driver's identity. Config is the maintenance log of how the car changed over time. Trusted Advisor is the mechanic who looks it over and says 'your tires are worn'.

Examples

A CPU alarm

aws cloudwatch put-metric-alarm \
  --alarm-name web-high-cpu \
  --namespace AWS/EC2 --metric-name CPUUtilization \
  --dimensions Name=AutoScalingGroupName,Value=web-asg \
  --statistic Average --period 300 --evaluation-periods 2 \
  --threshold 80 --comparison-operator GreaterThanThreshold \
  --alarm-actions arn:aws:sns:eu-west-1:111122223333:ops-alerts

If average CPU stays above 80% for two 5-minute periods, notify the SNS topic.

Who deleted that bucket? (CloudTrail)

aws cloudtrail lookup-events \
  --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket \
  --max-results 5 \
  --query "Events[].[EventTime,Username,EventName]" --output table

Lookup covers recent management events; for long-term analysis send the trail to S3.

A Config rule (CloudFormation)

Resources:
  EncryptedVolumesRule:
    Type: AWS::Config::ConfigRule
    Properties:
      ConfigRuleName: encrypted-volumes
      Source:
        Owner: AWS
        SourceIdentifier: ENCRYPTED_VOLUMES
      Scope:
        ComplianceResourceTypes: ["AWS::EC2::Volume"]

How it works

Services publish metrics to CloudWatch automatically (basic metrics at regular intervals; detailed monitoring is more frequent). Agents add memory, disk and application logs. Alarms compare metrics with thresholds and fire actions.

CloudTrail delivers event logs to S3 and optionally CloudWatch Logs, recording identity, source IP, time and request parameters. Config snapshots resource state and flags noncompliance.

  Resources --metrics/logs--> CloudWatch --alarm--> SNS / Auto Scaling
  Every API call ----------> CloudTrail --> S3 / audit
  Resource config changes -> Config --rules--> compliant / non-compliant
  Account best practices -> Trusted Advisor --> recommendations

Why does it exist?

You can't fix, secure or optimise what you can't see. Monitoring catches problems early, auditing answers 'who did that', and configuration tracking supports compliance and incident response.

When to use it

Turn on CloudTrail in every account, alarm on key health metrics, use Config for compliance rules, and review Trusted Advisor regularly for cost and security wins.

When not to use it

CloudWatch is not an audit log of user actions (use CloudTrail). CloudTrail is not a performance monitor (use CloudWatch). Trusted Advisor is not a complete security audit.

Common mistakes

  • Mixing up CloudWatch and CloudTrail.

  • Creating alarms nobody receives or acts on.

  • Not retaining CloudTrail logs long enough for investigations.

  • Alerting on too many noisy metrics until the team ignores them.

  • Assuming all Trusted Advisor checks are available on every support plan.

  • Expecting CloudTrail Event history to keep events forever; create a trail to S3 for long-term retention.

  • Assuming S3 object reads are in CloudTrail by default; data events must be turned on.

  • Expecting EC2 memory usage in CloudWatch without installing the CloudWatch agent.

  • Confusing the SLA (the contract) with the SLO (the target) or the SLI (the measurement).

Practice exercises

  1. Easy:

    Which service answers each: 'Why is the app slow?', 'Who changed the security group?', 'Is every volume encrypted?'

  2. Medium:

    Create an alarm on a metric and an SNS email subscription. Trigger it and confirm the notification.

  3. Medium:

    Use the cron builder tool to design a schedule for a nightly EventBridge rule that runs a cleanup job.

  4. Hard:

    Outline an incident investigation using CloudWatch, CloudTrail and Config for 'an S3 bucket became public overnight'.

  5. Easy:

    Define SLI, SLO and SLA for a checkout API in one sentence each.

  6. Medium:

    Write a Logs Insights query idea to find the 20 most recent errors in a Lambda function's log group, and say which log group and stream you would expect.

Interview questions

CloudWatch vs CloudTrail?

CloudWatch monitors performance and operational data (metrics, logs, alarms); CloudTrail records API activity for governance and audit.

What is AWS Config used for?

Recording resource configuration history and evaluating it against compliance rules.

What are Trusted Advisor categories?

Cost optimization, performance, security, fault tolerance, service limits, and operational excellence.

Exam-style: Which service logs API calls made in an AWS account?

AWS CloudTrail.

Exam-style: Which service can alarm when CPU utilisation exceeds a threshold?

Amazon CloudWatch.

Exam-style: Which service traces requests through a microservices application to find bottlenecks?

AWS X-Ray.

Exam-style: How long does CloudTrail Event history keep management events, and how do you keep them longer?

90 days. Create a trail that delivers logs to an S3 bucket (and analyse them with Athena or CloudTrail Lake).

Exam-style: Where can you see scheduled AWS maintenance that affects your own EC2 instances?

The account health view of the AWS Health Dashboard.

Exam-style: What does a customer receive if AWS fails to meet a service's SLA?

Service credits.

What are the three CloudWatch alarm states?

OK, ALARM and INSUFFICIENT_DATA.

What was Amazon EventBridge formerly called?

CloudWatch Events.