โšก Onwuachi Control Plane

CloudTrail: API Audit and Event History

Overview

CloudTrail records every API call made in your AWS account โ€” who called what, when, from where, and with what result. It is the audit log for the AWS control plane. Every CLI command, console action, and SDK call creates a CloudTrail event.

Why It Matters

Without CloudTrail, there’s no answer to “who terminated that instance?” or “who changed that security group?” CloudTrail is the foundation for security auditing, compliance, incident investigation, and automated response to unauthorized API activity.

Where It Fits

DOP-C02 Domain 4 โ€” Monitoring and Logging

AWS API call (CLI / Console / SDK) | v CloudTrail (records event) | +– S3 bucket (raw gzipped JSON, long-term storage) | +– CloudWatch Logs (real-time alerting pipeline) | v Metric Filter โ†’ Alarm โ†’ SNS


The Big Picture

CloudTrail Event fields:

Who: userIdentity (IAM user, role, service) What: eventName (TerminateInstances, DeleteBucket, PutBucketPolicy) When: eventTime Where: sourceIPAddress Which: requestParameters (instance IDs, bucket names, etc.) Result: errorCode (present only on failures)


Core Concepts

Three event types:

Management Events (default, free first copy per region):

Data Events (extra cost ~$0.10/100k):

Insights Events (extra cost):

Trail configuration โ€” exam-relevant settings:

Multi-region trail โ€” one trail covers all regions (recommended, default for new trails) Log file validation โ€” SHA-256 hash chain proves logs weren’t tampered with S3 bucket โ€” where raw trail logs land (gzipped JSON, ~15 min delay) CloudWatch Logs โ€” ship trail events for real-time alerting (separate config)

LookupEvents โ€” free, no trail needed:

aws cloudtrail lookup-events \
  --max-results 5 \
  --query "Events[*].{Time:EventTime,User:Username,Event:EventName}" \
  --output table

Last 90 days of management events, queryable for free without a trail configured. Use for quick incident investigation.

Alerting pipeline โ€” the exam standard pattern:

CloudTrail โ†’ CloudWatch Logs integration | v Metric Filter (pattern: “DeleteBucket” or “{ $.errorCode = “AccessDenied” }”) | v CloudWatch Alarm (threshold > 0) | v SNS โ†’ email / Lambda

Use case: alert when someone deletes an S3 bucket, when root account is used, or when there are repeated authorization failures.

Global service events: IAM, STS, Route 53 events only log in us-east-1. A multi-region trail captures them because it includes us-east-1. A single-region trail in another region misses them.


Real-World Example

Live check in devopslab, account 046685909731:

describe-trails returned empty โ€” no custom trail configured. Account relies on default 90-day event history only.

lookup-events returned live activity from the ops instance i-065af3b16c9f91e27:

This confirms CloudTrail event history is always on even without a trail โ€” the ops instance’s normal activity is fully auditable for free.

What a trail adds beyond free event history:

Platform-foundation gap: No trail configured โ€” all API activity only retained 90 days. Adding a multi-region trail shipping to CloudWatch Logs would enable alerting on unauthorized API calls.


Engineering Analogy

CloudTrail is the AWS equivalent of Linux auditd โ€” every syscall logged with who, what, when, and result. lookup-events is ausearch. The CloudTrail โ†’ CloudWatch Logs โ†’ Metric Filter pipeline is the equivalent of auditd โ†’ syslog โ†’ grep โ†’ alerting.


Best Practices


Common Mistakes


Pro Tip

aws cloudtrail lookup-events is free for the last 90 days and requires no trail โ€” use it first during incident investigation before assuming you need a trail. Filter by event name, resource, or time window: --lookup-attributes AttributeKey=EventName,AttributeValue=TerminateInstances


Key Takeaways


Related Articles


References

System Context

โ† Back to Kb