CloudTrail: who did what, and when

“Who opened port 22 to the whole internet?” “Who deleted that bucket?” These are the questions AWS CloudTrail answers, because it records every API call in your account, with who made it, from which IP, when and with what parameters, whether the call came from the console, the CLI or a script.

You’ll make a risky change on purpose and then find yourself in the records. After that you’ll set up saat-trail, a multi-Region trail that keeps every event in your own S3 bucket. This trail stays for the rest of the course, since the later lessons on Config, GuardDuty and AccessDenied errors depend on it.

TimeYou needBy the end you can
45 minutessaat-vpc (only to create a test security group), your laptop signed in as saat-admin. Cost: no CloudTrail charge for the first copy of management events; a few cents a month of S3 storage for the trail.Search event history, read a CloudTrail event the way an investigator would, create a multi-Region trail with the right bucket policy, and know where global service events get recorded.

What it is, in one line

AWS CloudTrail records the API calls made in your AWS account, so you can see who did what, when, and from where.

In Simple Words

The CCTV at the office entrance

Most offices have a camera at the door and a visitor register, so if a laptop goes missing, security can check who came in, at what time and which badge they used. CloudTrail is that camera and register for your AWS account, where every action, whether it’s “open this door” or “delete that file”, gets written down with the person’s badge, the time and where they came from. The building keeps 90 days of footage by itself, and if you want it for years, or want footage from every floor in one place, you copy it to your own locker, which is what a trail does.

Engineer's View

What CloudTrail really records

Each event is a piece of JSON with eventTime, eventName, eventSource, userIdentity (an IAM user, an assumed role with its session name, or an AWS service), sourceIPAddress, userAgent, requestParameters, responseElements and, when the call failed, an errorCode such as AccessDenied.

Event history gives you 90 days of management events per Region at no cost, and you can search it by one attribute at a time. Global services such as IAM, Organizations and (in some cases) STS record in us-east-1. A trail sends events to an S3 bucket, and optionally to CloudWatch Logs, usually from all Regions, and a multi-Region trail picks up the global service events too.

Log file validation adds hourly digest files signed by AWS, so you can prove logs weren’t changed.

Data events like S3 object reads and Lambda invocations are off by default because there are so many of them and they cost money. Events normally show up within about five minutes, and when teams want SQL-style queries over years of events they use CloudTrail Lake or Athena on the trail bucket.

How it works, step by step

Follow one API call through the system.

1You make a change

authorize-security-group-ingress goes to the EC2 API in Mumbai, signed with your saat-admin credentials.

AWS CloudTrail flow: API call, event recorded, event history and trail to S3

2CloudTrail records it

Within a few minutes the event is in Mumbai’s event history, with your IAM user, your public IP and the exact rule you added.

3A trail keeps a copy

saat-trail writes that same event, along with events from every other Region, as compressed JSON files into your S3 bucket, and there you decide how long to keep them.

4Choose what to record

Some event types are off until you turn them on:

AWS CloudTrail event types: management, data, Insights and network activity events

The baseline for most teams is one multi-Region trail with management events. They add data events only for sensitive buckets, because a busy bucket can throw out millions of events a day.

✅ Checkpoint: You can name the key fields of an event, explain how event history differs from a trail, and say where IAM events get recorded.

Hands-on lab: investigate with AWS CloudTrail and build a trail

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Sign in and load saat-vpc:

cd C:\aws-lab
aws login --profile saat-admin
$env:AWS_PROFILE = 'saat-admin'
$v = Get-Content C:\aws-lab\saat-vpc.json | ConvertFrom-Json
$acct = aws sts get-caller-identity --query Account --output text

1Make a risky change, then undo it

Paste the whole block. The group never gets attached to anything:

$sg = aws ec2 create-security-group --group-name lab25-test --description "CloudTrail test" --vpc-id $v.VpcId --query GroupId --output text
aws ec2 authorize-security-group-ingress --group-id $sg --protocol tcp --port 22 --cidr 0.0.0.0/0 | Out-Null
aws ec2 delete-security-group --group-id $sg
$sg

You should see something like this:

sg-0f1e2d3c4b5a69788

The group only existed for a few seconds, but in a real account that’s plenty of time for someone to ask “who did this?” later on.

2Find the event and read it

Paste the whole block. Events normally show up within five minutes:

do { Start-Sleep 30; $e = aws cloudtrail lookup-events --lookup-attributes "AttributeKey=ResourceName,AttributeValue=$sg" --query "Events[?EventName=='AuthorizeSecurityGroupIngress'] | [0]" --output json | ConvertFrom-Json } until ($e)
$d = $e.CloudTrailEvent | ConvertFrom-Json
$d | Select-Object eventTime, eventName, sourceIPAddress, @{n='who';e={$_.userIdentity.arn}}
$d.requestParameters.ipPermissions.items.ipRanges.items.cidrIp
aws cloudtrail lookup-events --lookup-attributes "AttributeKey=ResourceName,AttributeValue=$sg" --query "Events[].EventName" --output text

You should see something like this:

eventTime       : 2026-10-20T18:42:17Z
eventName       : AuthorizeSecurityGroupIngress
sourceIPAddress : 203.0.113.25
who             : arn:aws:iam::111122223333:user/yourname.admin

0.0.0.0/0
DeleteSecurityGroup     AuthorizeSecurityGroupIngress   CreateSecurityGroup

There’s the whole picture: your user, your laptop’s public IP, the exact rule, and the group’s life from create to delete. When someone asks “who touched this?”, searching by resource name is usually the quickest way to find out.

AWS CloudTrail lab output: who opened port 22, from where, and trail logging
Who opened port 22 and from where, plus the trail logging. It should look something like this.

3Create the trail bucket

Paste this whole block:

$bucket = "saat-trail-$acct-ap-south-1-an"
aws s3api create-bucket --bucket $bucket --bucket-namespace account-regional --region ap-south-1 --create-bucket-configuration LocationConstraint=ap-south-1 | Out-Null
aws s3api put-bucket-tagging --bucket $bucket --tagging 'TagSet=[{Key=course,Value=saatvedha-aws},{Key=purpose,Value=cloudtrail}]'
'{ "Rules": [ { "ID": "expire-90-days", "Status": "Enabled", "Filter": {}, "Expiration": { "Days": 90 } } ] }' | Set-Content trail-lifecycle.json
aws s3api put-bucket-lifecycle-configuration --bucket $bucket --lifecycle-configuration file://trail-lifecycle.json
aws s3api get-bucket-lifecycle-configuration --bucket $bucket --query "Rules[0].[ID,Expiration.Days]" --output text

You should see this:

expire-90-days  90

Ninety days keeps the lab cheap. Companies often hold trail logs for one to seven years and move the older files to Glacier.

4Create the trail with a correct bucket policy

You’ll try it without a bucket policy first, and that’s the first break below. This is the version that works.

Paste this whole block:

@'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AWSCloudTrailAclCheck",
      "Effect": "Allow",
      "Principal": { "Service": "cloudtrail.amazonaws.com" },
      "Action": "s3:GetBucketAcl",
      "Resource": "arn:aws:s3:::BUCKET",
      "Condition": { "StringEquals": { "aws:SourceArn": "arn:aws:cloudtrail:ap-south-1:ACCT:trail/saat-trail" } }
    },
    {
      "Sid": "AWSCloudTrailWrite",
      "Effect": "Allow",
      "Principal": { "Service": "cloudtrail.amazonaws.com" },
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::BUCKET/AWSLogs/ACCT/*",
      "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control", "aws:SourceArn": "arn:aws:cloudtrail:ap-south-1:ACCT:trail/saat-trail" } }
    }
  ]
}
'@ -replace 'BUCKET', $bucket -replace 'ACCT', $acct | Set-Content trail-bucket-policy.json
aws s3api put-bucket-policy --bucket $bucket --policy file://trail-bucket-policy.json
aws cloudtrail create-trail --name saat-trail --s3-bucket-name $bucket --is-multi-region-trail --enable-log-file-validation --tags-list Key=course,Value=saatvedha-aws --query "[Name,IsMultiRegionTrail,LogFileValidationEnabled]" --output text
aws cloudtrail start-logging --name saat-trail
aws cloudtrail get-trail-status --name saat-trail --query IsLogging

You should see this:

saat-trail      True    True
true

Give it about ten minutes and then check the bucket. The files are grouped by account, Region and date:

aws s3 ls "s3://$bucket/AWSLogs/$acct/CloudTrail/" --recursive | Select-Object -First 3

You should see something like this:

2026-10-20 18:58:12       1845 AWSLogs/111122223333/CloudTrail/ap-south-1/2026/10/20/111122223333_CloudTrail_ap-south-1_20261020T1855Z_a1B2c3D4e5F6g7H8.json.gz
2026-10-20 18:59:40        912 AWSLogs/111122223333/CloudTrail/us-east-1/2026/10/20/111122223333_CloudTrail_us-east-1_20261020T1855Z_i9J0k1L2m3N4o5P6.json.gz
2026-10-20 19:01:03       2210 AWSLogs/111122223333/CloudTrail/ap-south-1/2026/10/20/111122223333_CloudTrail_ap-south-1_20261020T1900Z_q7R8s9T0u1V2w3X4.json.gz

✅ Checkpoint: You found who opened port 22 and from which IP, saat-trail is logging from all Regions with log file validation on, and files are turning up in your bucket. Keep both the trail and the bucket.

Break It, Then Fix It

These two catch out nearly everyone the first time they use CloudTrail.

1Break it: a trail bucket without a policy

If you’ve already run step 4, take the policy off first. In a new account, this is the order people usually try things in anyway.

Paste the whole block:

aws cloudtrail delete-trail --name saat-trail
aws s3api delete-bucket-policy --bucket $bucket
aws cloudtrail create-trail --name saat-trail --s3-bucket-name $bucket --is-multi-region-trail --enable-log-file-validation

You’ll get this error back:

An error occurred (InsufficientS3BucketPolicyException) when calling the CreateTrail operation: Incorrect S3 bucket policy is detected for bucket: saat-trail-111122223333-ap-south-1-an

Before it creates the trail, CloudTrail checks that it can read the bucket ACL and write under AWSLogs/ACCOUNT/. The console adds this policy for you, but the CLI and infrastructure code don’t. Fix: apply the policy, then create and start the trail:

aws s3api put-bucket-policy --bucket $bucket --policy file://trail-bucket-policy.json
aws cloudtrail create-trail --name saat-trail --s3-bucket-name $bucket --is-multi-region-trail --enable-log-file-validation --tags-list Key=course,Value=saatvedha-aws | Out-Null
aws cloudtrail start-logging --name saat-trail
aws cloudtrail get-trail-status --name saat-trail --query IsLogging

You should see this:

true

2Break it: look for an IAM change in Mumbai

Create a test IAM policy and delete it, then look for it in Mumbai’s event history:

'{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": "s3:DeleteBucket", "Resource": "*" } ] }' | Set-Content p25.json
$pArn = aws iam create-policy --policy-name lab25-test --policy-document file://p25.json --query Policy.Arn --output text
aws iam delete-policy --policy-arn $pArn
Start-Sleep 300
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=CreatePolicy --region ap-south-1 --query "length(Events)"

You should see this:

0
CloudTrail problems: InsufficientS3BucketPolicyException and IAM events only in us-east-1
Both problems and their fixes. Something like this.

No error and no event either. IAM is a global service, so its events are recorded in us-east-1 (N. Virginia) and not in the Region you’re working in, and engineers lose a lot of time on this during investigations. Fix: search us-east-1 for IAM, STS and Organizations changes, or search your multi-Region trail, where they sit under the us-east-1 prefix:

aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=CreatePolicy --region us-east-1 --query "Events[0].[EventName,Username]" --output text
Remove-Item p25.json

You should see something like this:

CreatePolicy    yourname.admin

✅ Checkpoint: You fixed InsufficientS3BucketPolicyException with the CloudTrail bucket policy, and you found an IAM event in us-east-1. saat-trail stays on for the rest of the course.

This happened at work

The weekend nobody could explain

At a retail company, the cloud team came in on a Monday and found 14 large GPU instances running in São Paulo, about USD 6,000 of compute burnt over the weekend, and nobody would admit to launching them. The security team opened CloudTrail event history in Mumbai, which was the only Region they used, and found nothing, because event history is per Region and they had no trail. Eventually someone thought to check São Paulo’s event history, and there were the RunInstances calls, made with an access key that belonged to a CI user and had been pushed to a public repository two days earlier. What they nearly missed was the CreateAccessKey event for a second key, made in IAM, which only showed up in us-east-1. Since then they run an organization-wide multi-Region trail into a locked bucket in a separate log archive account, query it with CloudTrail Lake, have GuardDuty on in all Regions, and use an SCP to deny the Regions they don’t use.

Common mistakes and troubleshooting

MistakeWhat happensWhat to do
Relying on event history only90 days, one Region at a time, management events onlyCreate a multi-Region trail to S3
Searching your Region for IAM changesNothing foundSearch us-east-1 or the trail
Trail bucket without the CloudTrail policyInsufficientS3BucketPolicyExceptionAdd the AclCheck and Write statements
Trail bucket in the same account admins controlLogs can be deleted by an attackerUse a separate log archive account and Object Lock
Turning on data events for every bucketHuge event volume and costEnable data events only where needed
No retention on the trail bucketStorage grows foreverLifecycle rules that match your policy

Interview questions

Click a question to open it. Each one is phrased the way an interviewer would ask it, and under it you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. Can you explain in simple words what AWS CloudTrail does?

Why they ask this: They want to know you’d know where to look when someone asks who changed something, since it’s one of the first services an admin opens in any investigation.

How you might answer: CloudTrail records the API calls made in your AWS account, and for each one it shows who made it, when, from which IP address and with what parameters. I usually describe it as a CCTV camera for the account, because whether someone clicks in the console or runs a CLI command, it leaves a record.

2. If you don’t set anything up, how far back can you look in CloudTrail event history?

Why they ask this: They’re checking you know the default limits before an incident happens, because a lot of people only find out the older events are gone when it’s too late.

How you might answer: Event history keeps 90 days of management events per Region, free. If we need to go back further, I’d set up a trail that delivers logs to S3, or use CloudTrail Lake.

3. Someone deleted a security group this morning and nobody admits it. How would you find out who did it?

Why they ask this: They want to see you can use CloudTrail on a real question and not only describe it, and that you know which fields in the event matter.

How you might answer: I’d search event history, or the trail, for the event name DeleteSecurityGroup, or use the group ID as the resource name. Then I’d open the event and read userIdentity, sourceIPAddress and eventTime, which tell me which user or role made the call, from where, and exactly when.

2–5 years experience

4. What’s the difference between management events and data events, and when would you turn on data events?

Why they ask this: They want to know you understand what CloudTrail records by default and what costs extra, since that affects your audit coverage and your bill.

How you might answer: Management events are control-plane actions, like creating or changing a resource, while data events are the high-volume actions on the data itself, such as S3 GetObject or Lambda Invoke. Data events are off by default and you pay for them, so I’d only turn them on for the buckets or functions where we need to know who read or called what.

5. A colleague says they changed an IAM policy yesterday, but you can’t find the event in your Region’s event history. What’s going on?

Why they ask this: It checks whether you know how global services are logged, which trips up a lot of people in real investigations.

How you might answer: IAM is a global service, so its events go to us-east-1 and not to the Region I’m working in. I’d switch event history to us-east-1, or search a multi-Region trail, and I’d expect to find the change there.

6. During an audit, someone asks how you can prove your CloudTrail logs were never changed. What would you tell them?

Why they ask this: They want to see you think about log integrity as well as log collection, which auditors and security teams care a lot about.

How you might answer: I’d make sure log file validation is on for the trail, because then CloudTrail writes signed digest files every hour. I can run aws cloudtrail validate-logs against those digests, and it tells me if any log file was changed or deleted.

Senior level

7. You’re asked to design audit logging for an organization with 60 AWS accounts. How would you set it up?

Why they ask this: They’re looking for governance thinking at scale, and in particular whether you keep the logs out of reach of the same people whose actions they record.

How you might answer: I’d create an organization trail from the management account or a delegated admin account, delivering to a bucket in a dedicated log archive account, and that bucket would have Object Lock, KMS encryption, tight access and lifecycle rules to Glacier. For searching I’d use CloudTrail Lake or Athena, and I’d add SCPs so nobody in the member accounts can stop or change the trail.

8. It’s 2 a.m. and you get an alert that a leaked access key is being used. How would you use CloudTrail to investigate?

Why they ask this: They want a clear incident response process under pressure, where you find everything the attacker did and don’t stop at disabling the key.

How you might answer: I’d search the trail or CloudTrail Lake for the AccessKeyId across all Regions and list every API call, source IP and resource it created or read. I’d also check us-east-1 for IAM changes like new users or new keys, because attackers often leave themselves a back door. Then I’d disable the key, remove whatever they created to keep access, and clean up the resources they launched.

Quick quiz

Q1. Where are IAM API events recorded in event history?

  1. Every Region
  2. us-east-1
  3. ap-south-1 only
  4. Nowhere
Show answer

B — IAM is global and records in us-east-1.

Q2. How long does event history keep management events?

  1. 7 days
  2. 30 days
  3. 90 days
  4. Forever
Show answer

C — For longer, use a trail or CloudTrail Lake.

Q3. Why did create-trail fail without a bucket policy?

  1. The bucket was public
  2. CloudTrail could not check and write to the bucket
  3. The trail name was taken
  4. Logging was off
Show answer

B — CloudTrail needs GetBucketAcl and PutObject permission.

Q4. Which field shows who made the call?

  1. eventSource
  2. userIdentity
  3. awsRegion
  4. requestID
Show answer

B — userIdentity holds the user, role or service.

Q5. What does log file validation give you?

  1. Faster delivery
  2. Proof that log files were not changed
  3. Data events
  4. Encryption
Show answer

B — Signed digest files let you validate the logs.

Quick recap

  • CloudTrail records who did what, when, and from where.
  • Event history gives you 90 days, one Region at a time, and only management events.
  • A multi-Region trail keeps every Region in your bucket, with validation on.
  • The trail bucket has to have the CloudTrail bucket policy.
  • IAM and the other global services record in us-east-1.

Next lesson

Lesson 26: AWS Config rules and resource timeline → Next you’ll record resource changes, look at a security group’s full history and have non-compliant resources flagged automatically.

Further reading: AWS CloudTrail

Want to go deeper into AWS CloudTrail? Read What is AWS CloudTrail? and Amazon S3 bucket policy for CloudTrail. You can also see the full plan for this course on the AWS Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.