Sub topic 1
What CloudTrail records and why it matters for auditing
AWS CloudTrail records API activity in your AWS account. Each record answers a basic audit question: who did what, when, from where, and on which resource. This chapter explains what CloudTrail captures, what it leaves out, and why that record is the base for the rest of this tutorial.
Prerequisites
This chapter assumes you already have the following:
- Basic AWS account and IAM concepts: users, roles, and policies.
- Familiarity with Amazon S3 buckets.
- Comfort reading JSON.
- Basic use of the AWS CLI, including configured credentials.
You do not need to have used CloudTrail before.
Why auditing needs a record of API calls
Almost everything that changes an AWS account is an API call. When you click "Create bucket" in the console, the console sends an API request on your behalf. The AWS CLI, the SDKs, CloudFormation, Terraform, and other AWS services acting for you all do the same. The API layer is the one place where all of this activity passes through, so a log of API calls gives a complete history of control-plane changes.
Auditing is the practice of reconstructing and checking that history. Typical reasons to do it:
- Security investigation. A security group was opened to the internet. Who opened it, and with which credentials?
- Compliance evidence. An auditor asks you to show who changed IAM policies during a quarter.
- Operational troubleshooting. A resource disappeared. Was it deleted by a person, a pipeline, or an automated process?
- Detecting abuse. Credentials used from an unexpected IP address or at an unusual time stand out in the record.
CloudTrail is the AWS service that produces this record. It is on by default for every account in a limited form (Event history, covered below), and you extend it by creating trails.
What CloudTrail records
CloudTrail records events. An event is one activity in your account, captured as a JSON record. The activity is usually an API call, but it can also be a console sign-in or an action taken by an AWS service on your behalf.
Several details of this behavior matter when you rely on the logs:
- Failed and denied calls are recorded too. A call rejected with
AccessDeniedstill produces an event, witherrorCodeanderrorMessagefields. These are often the most interesting events, because they show someone probing for permissions. - Every access path is covered. Console, CLI, SDK, and service-to-service calls all appear. The
userAgentfield tells you which path was used. - Delivery is near real time, not instant. Events typically reach a trail's S3 bucket within about five minutes of the API call. Do not treat CloudTrail as a live stream.
- Events are scoped by Region. Most events are recorded in the Region where the call was made. Global services, such as IAM, report to a home Region, which is why multi-Region trails matter. A later chapter covers this.
What CloudTrail does not record
CloudTrail is not a general-purpose logging system. Knowing its boundaries keeps you from assuming coverage you do not have.
| You want to know | Does CloudTrail answer it? | Where to look instead |
|---|---|---|
| Who created or deleted an EC2 instance | Yes, as a management event | CloudTrail |
| Who read an object in an S3 bucket | Only if data events are enabled for that bucket | CloudTrail data events, S3 server access logs |
| What commands ran inside an instance | No | OS logs, an agent such as the CloudWatch agent, or Systems Manager session logs |
| What network traffic reached an instance | No | VPC Flow Logs |
| What an application did internally | No | Application logs sent to CloudWatch Logs |
| How much CPU a resource used | No | CloudWatch metrics |
| Whether a resource's configuration drifted over time | Partly (the API calls that changed it) | AWS Config |
The key distinction is between the control plane and the data plane. The control plane is the set of calls that create, configure, and delete resources, such as RunInstances or PutBucketPolicy. The data plane is the activity that uses those resources, such as reading an S3 object or invoking a Lambda function. CloudTrail records the control plane by default. Data plane activity is recorded only when you opt in, and that costs more. The next chapters cover this choice.
The shape of an event
Every CloudTrail event has the same core fields. This trimmed record shows someone stopping a trail's logging.
{
"eventVersion": "1.09",
"userIdentity": {
"type": "IAMUser",
"arn": "arn:aws:iam::123456789012:user/alice",
"accountId": "123456789012",
"userName": "alice"
},
"eventTime": "2026-11-20T09:15:42Z",
"eventSource": "cloudtrail.amazonaws.com",
"eventName": "StopLogging",
"awsRegion": "us-east-1",
"sourceIPAddress": "203.0.113.10",
"userAgent": "aws-cli/2.x",
"requestParameters": { "name": "org-audit-trail" },
"readOnly": false,
"eventType": "AwsApiCall",
"recipientAccountId": "123456789012"
}Map the fields to audit questions:
| Question | Field |
|---|---|
| Who? | `userIdentity` (type, ARN, user name, or assumed role) |
| What? | `eventSource` (the service) and `eventName` (the API action) |
| When? | `eventTime`, always in UTC |
| Where from? | `sourceIPAddress` and `userAgent` |
| On what? | `requestParameters`, and sometimes `resources` |
| Where in AWS? | `awsRegion` and `recipientAccountId` |
| Did it work? | The absence of `errorCode`, or its presence with `errorMessage` |
Read this event as a sentence: on 20 November 2026 at 09:15 UTC, IAM user alice, using the AWS CLI from 203.0.113.10, called StopLogging on the trail org-audit-trail. There is no errorCode, so the call succeeded and the trail stopped recording. A successful StopLogging is a high-priority event in any audit, because it is how someone hides later activity. The next chapter walks through the record field by field.
Event history versus trails
CloudTrail gives you two ways to see events. They differ in scope and retention.
Event history is available in every account without setup. It shows the last 90 days of management events in each Region. You can search it in the console or with aws cloudtrail lookup-events. It is read-only, and you cannot extend its retention or add data events to it.
A trail is a configuration you create. It delivers events continuously to an S3 bucket, and optionally to CloudWatch Logs and EventBridge. Logs in S3 stay as long as you keep them, so a trail is how you get long-term retention, data events, and a copy of the logs you control.
Here is a quick Event history search for the event above:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=StopLogging \
--max-results 10This query searches the current Region only, covers the last 90 days, and returns management events only. For anything older, or any data event, you need a trail.
How the pieces fit together
The rest of the tutorial follows this diagram. Later chapters cover event categories, creating trails, S3 layout, multi-Region and organization trails, integrity validation, querying, alerting, protection, and investigation.
Three event categories at a glance
CloudTrail groups events into categories, and the category decides whether an event is recorded by default.
- Management events are control-plane operations such as creating an IAM role or changing a security group. Event history includes them by default.
- Data events are data-plane operations such as S3 object reads or Lambda invocations. They are high volume, off by default, and billed per event.
- Insights events flag unusual API call rates or error rates compared with your account's normal pattern. You enable them on a trail.
Because the categories control both coverage and cost, choosing which to log is one of the main design decisions you will make.
Common mistakes
- Relying on Event history for compliance. Ninety days is short, and the history is per Region. Create a trail for anything you must retain.
- Assuming object reads are logged. Without data events, nobody can tell you who downloaded a file from a bucket.
- Treating CloudTrail as a security control. CloudTrail observes and records. It does not block anything. Prevention comes from IAM policies and service control policies.
- Ignoring failed calls. A burst of
AccessDeniederrors from one identity is often the first sign of a compromised key. - Forgetting that the log can be attacked. Anyone who can stop a trail or delete its bucket contents can erase their tracks. Later chapters cover protections.
Summary
CloudTrail records API activity, including failures, as JSON events that identify the actor, action, time, source, and target. By default it covers management events only, and you can search them for 90 days per Region in Event history. A trail extends this with long-term storage, data events, and integration with alerting. CloudTrail does not see inside your instances, your network traffic, or your application behavior, so it is one part of an audit toolkit.
Exercise
A teammate says, "We have CloudTrail on by default, so we can find out who downloaded the file payroll.csv from our S3 bucket last quarter." Give two reasons this may not be true.
Show answer
First, downloading an object is a data event, and data events are not recorded by default. Without a trail that has S3 data events enabled for that bucket, no record of the download exists. Second, Event history keeps only 90 days of management events per Region, so activity from last quarter may be outside the window even if it had been recorded. A trail with data events enabled before the download is the way to get this evidence.
Exercise
Using the example event in this chapter, which fields would you use to determine who made the call, from where, and whether it succeeded?
Show answer
Use userIdentity (type IAMUser, user name alice, with its ARN) to identify the actor. Use sourceIPAddress (203.0.113.10) and userAgent (aws-cli/2.x) to see where and how the call came from. The event has no errorCode field, so the call succeeded. If it had failed, errorCode and errorMessage would be present.