0Pricing
AWS Solutions Architect · Lesson

CloudTrail Trails and Event History

Create management and data event trails, deliver logs to S3 and CloudWatch Logs, and search the 90-day event history in the console.

CloudTrail Trails and Event History is a free AWS Solutions Architect lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is AWS CloudTrail?

AWS CloudTrail is a service that records every API call made in your AWS account — whether from the console, CLI, SDK, or another AWS service. Each record is called a CloudTrail event and contains the API action, the requester's identity, the source IP, the request parameters, and the response. CloudTrail is the foundation of AWS security auditing, compliance, and operational investigation. For the SAA-C03 exam, it is the answer whenever a question asks 'who made this change?'

Event History: Free 90-Day Lookback

By default, every AWS account has access to CloudTrail Event History — a 90-day rolling record of management events viewable in the console or queryable via the CLI. You can filter by resource name, resource type, event name, or username. Event History is free, requires no configuration, and is available immediately. It is the quickest way to investigate recent changes, but for longer retention or more powerful queries you must create a Trail.

# Search event history for who deleted an S3 bucket in the last 7 days
aws cloudtrail lookup-events \
  --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket \
  --start-time $(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ) \
  --query 'Events[].{Time:EventTime,User:Username,Detail:CloudTrailEvent}' \
  --output table

Creating a CloudTrail Trail

A Trail is a CloudTrail configuration that delivers events continuously to an S3 bucket (and optionally to CloudWatch Logs). You pay for S3 storage and data transfer. A Trail can be scoped to a single Region or configured as a multi-region trail that captures events from every current and future Region in your account. For the SAA-C03 exam, always recommend a multi-region trail — single-region trails miss activity in other Regions and are considered a security gap.

# Create a multi-region trail delivering to S3
aws cloudtrail create-trail \
  --name OrgAuditTrail \
  --s3-bucket-name my-cloudtrail-logs-111122223333 \
  --is-multi-region-trail \
  --include-global-service-events \
  --enable-log-file-validation

# Start logging (trails are created in 'paused' state)
aws cloudtrail start-logging --name OrgAuditTrail

Management Events vs Data Events

CloudTrail records two categories of events: Management events (also called control-plane events) record operations on resources — creating an EC2 instance, modifying a security group, attaching an IAM policy. These are enabled by default in every trail at no extra per-event charge. Data events record object-level operations — S3 GetObject, PutObject, DeleteObject, or Lambda Invoke. Data events can be very high volume and incur additional charges, so they must be explicitly enabled per resource or resource type.

# Add data event logging for all S3 objects in a specific bucket
aws cloudtrail put-event-selectors \
  --trail-name OrgAuditTrail \
  --event-selectors '[
    {
      "ReadWriteType": "All",
      "IncludeManagementEvents": true,
      "DataResources": [
        {
          "Type": "AWS::S3::Object",
          "Values": ["arn:aws:s3:::my-sensitive-bucket/"]
        }
      ]
    }
  ]'

CloudTrail and CloudWatch Logs Integration

Delivering CloudTrail events to CloudWatch Logs enables real-time alerting on API activity. You can create metric filters on the CloudTrail log group to count specific events — for example, count DeleteBucket or CreateUser calls — and then set CloudWatch alarms to alert your security team within minutes of a suspicious action. This is a core pattern in the CIS AWS Foundations Benchmark, which the SAA-C03 exam frequently references.

# Update a trail to also deliver to CloudWatch Logs
aws cloudtrail update-trail \
  --name OrgAuditTrail \
  --cloud-watch-logs-log-group-arn arn:aws:logs:us-east-1:111122223333:log-group:CloudTrail/Logs:* \
  --cloud-watch-logs-role-arn arn:aws:iam::111122223333:role/CloudTrailCWLogsRole

# Create a metric filter for root account login
aws logs put-metric-filter \
  --log-group-name CloudTrail/Logs \
  --filter-name RootLogin \
  --filter-pattern '{$.userIdentity.type = "Root" && $.eventName = "ConsoleLogin"}' \
  --metric-transformations metricName=RootLogins,metricNamespace=CISBenchmark,metricValue=1

Global Service Events

Some AWS services — notably IAM, STS, Route 53, and CloudFront — are global and log their API calls as global service events. These events are always recorded in the us-east-1 Region regardless of where the operation was initiated. When creating a trail, enable --include-global-service-events so IAM user creation, policy changes, and STS role assumptions are captured. If you have multiple Region-specific trails, enable global service events in only one to avoid duplicate log records.

# Verify that global service events are enabled on a trail
aws cloudtrail get-trail \
  --name OrgAuditTrail \
  --query 'Trail.{MultiRegion:IsMultiRegionTrail,GlobalServiceEvents:IncludeGlobalServiceEvents}'

S3 Bucket Policy for CloudTrail Logs

CloudTrail requires a specific S3 bucket policy that grants the CloudTrail service principal (cloudtrail.amazonaws.com) permission to call GetBucketAcl and PutObject on the bucket. AWS enforces that the bucket is not publicly accessible and that Object Ownership is set to Bucket Owner Enforced. Never store CloudTrail logs in the same bucket your application uses — this creates a circular dependency where access to audit logs is disrupted if the application bucket is locked down.

# Minimum S3 bucket policy for CloudTrail (abbreviated)
# {
#   "Version": "2012-10-17",
#   "Statement": [
#     {
#       "Sid": "AWSCloudTrailAclCheck",
#       "Effect": "Allow",
#       "Principal": {"Service": "cloudtrail.amazonaws.com"},
#       "Action": "s3:GetBucketAcl",
#       "Resource": "arn:aws:s3:::my-cloudtrail-logs-111122223333"
#     },
#     {
#       "Sid": "AWSCloudTrailWrite",
#       "Effect": "Allow",
#       "Principal": {"Service": "cloudtrail.amazonaws.com"},
#       "Action": "s3:PutObject",
#       "Resource": "arn:aws:s3:::my-cloudtrail-logs-111122223333/AWSLogs/111122223333/*",
#       "Condition": {"StringEquals": {"s3:x-amz-acl": "bucket-owner-full-control"}}
#     }
#   ]
# }

Organisation Trails

In an AWS Organisation, you can create an organisation trail from the management account that automatically applies to all member accounts — current and future. Member accounts cannot modify or delete the organisation trail, ensuring audit coverage cannot be evaded. Organisation trails deliver logs to a centralised S3 bucket with per-account prefixes, enabling a security team to query all accounts' audit logs in one place using Athena or a SIEM tool.

# Create an organisation trail from the management account
aws cloudtrail create-trail \
  --name OrgCentralTrail \
  --s3-bucket-name central-org-cloudtrail-logs \
  --is-multi-region-trail \
  --is-organization-trail \
  --include-global-service-events \
  --enable-log-file-validation

aws cloudtrail start-logging --name OrgCentralTrail

Athena Integration for Log Analysis

CloudTrail logs delivered to S3 are in JSON format. You can use the Amazon Athena integration in the CloudTrail console to create a Glue table automatically partitioned by account, Region, and date. This lets you query months of API history using standard SQL without loading data into a database. Partition by date in your queries (WHERE year='2024' AND month='01') to avoid full-table scans and control Athena costs.

-- Query CloudTrail logs in Athena for IAM policy changes in January 2024
SELECT
  eventtime,
  useridentity.arn AS principal,
  eventname,
  requestparameters
FROM cloudtrail_logs_111122223333
WHERE year = '2024'
  AND month = '01'
  AND eventsource = 'iam.amazonaws.com'
  AND eventname IN ('PutUserPolicy','AttachRolePolicy','CreateUser')
ORDER BY eventtime DESC
LIMIT 100;

Querying Event History vs Trail Logs

There are two ways to search CloudTrail records: Event History in the console (last 90 days, management events only, limited filters) and Trail logs in S3/Athena (unlimited retention, data events too, full SQL power). For exam scenarios: if the question asks to investigate an event older than 90 days, or to query data-plane events (S3 GetObject, Lambda Invoke), always recommend querying Trail logs via Athena. If the question asks for the simplest approach to investigate a recent management event, Event History is sufficient.

Key CloudTrail Facts for the Exam

Memorise these for the SAA-C03 exam: CloudTrail is not real-time — it can take up to 15 minutes to deliver events to S3 (use CloudWatch Logs for near-real-time alerting). Event History is 90 days for management events only. Data events must be explicitly enabled and cost extra. Log file validation uses SHA-256 hashes to detect tampering. Global service events (IAM, STS, Route 53) only appear in us-east-1. Organisation trails cannot be disabled by member accounts.

Quick Check

Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.

Lesson Recap

In this lesson you learned: Event History gives free 90-day management event access, Trails provide continuous delivery to S3 with configurable retention and optional data events, and organisation trails apply to all member accounts and cannot be disabled by them. Next up we explore CloudTrail Insights and log file integrity verification.

Frequently asked questions

Is the “CloudTrail Trails and Event History” lesson free?

Yes — the full text of “CloudTrail Trails and Event History” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.

What will I learn in “CloudTrail Trails and Event History”?

Create management and data event trails, deliver logs to S3 and CloudWatch Logs, and search the 90-day event history in the console. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AWS Solutions Architect?

No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “CloudTrail Trails and Event History” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AWS Solutions Architect lesson?

Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. CloudTrail Trails and Event History
  2. CloudTrail Insights and Log File Integrity
  3. AWS Config Rules and Remediation
  4. Conformance Packs and Organisation Trails
← Back to AWS Solutions Architect