Stop 14 · Monitoring, Security & Cost OptimizationTopics · 3/10

AWS CloudTrail

Part of the AWS Roadmap

In short

Someone deleted a production S3 bucket on Friday night. Who? From which IP? Using which role? CloudTrail is the account's CCTV, and without it that question has no answer.

CloudTrail records API activity in your account, showing who did what, when and from where. Event history shows the last 90 days of management events, and a trail delivers logs to S3 for longer retention and analysis.

The jaadu in a jewellery shop's back room watches a wall of small CCTV monitors showing different counters, pointing at one clip.

Think of it like this

The CCTV recorder in the jewellery shop

A jeweller in Zaveri Bazaar has cameras on every counter. Each clip shows who opened which drawer and when. The recorder keeps the last few months on its own disk, and the owner copies footage to a safe archive for years. CloudTrail records every API call, event history keeps 90 days, and a trail copies everything to S3 for as long as you need.

Watch it happen

One API call, recorded

Developer (role)
S3 API
CloudTrail
Trail bucket

DeleteBucket

1/4Ravi, using the role dev-admin, runs aws s3 rb from his laptop.

The big ideas

What you need to know

Management events

Control-plane actions like creating instances, changing IAM or deleting buckets. Recorded by default in event history.

Data events

Object-level actions like S3 GetObject or Lambda Invoke. High volume and extra cost, so enable them only where needed.

Multi-Region trail

Create one trail covering all Regions, or an organisation trail for all accounts, so nothing slips through in a Region you don't use.

Protect the logs

Turn on log file validation and lock down the bucket, ideally in a separate logging account, so attackers can't erase their tracks.

See it in code

Walk through the code

bash
1# Who deleted buckets in the last 90 days?2aws cloudtrail lookup-events \3  --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket \4  --query "Events[].[EventTime,Username,CloudTrailEvent]" \5  --max-results 106 7# Keep everything long-term: a multi-Region trail to S38aws cloudtrail create-trail \9  --name org-audit \10  --s3-bucket-name acme-cloudtrail-logs \11  --is-multi-region-trail \12  --enable-log-file-validation13 14aws cloudtrail start-logging --name org-audit

1/4Search event history by event name. You can also filter by user name or resource.

AWS CLI v2. The bucket needs a policy allowing CloudTrail to write to it. The console sets this up for you.

Save yourself the pain

Common mistakes

Oops

Relying on event history alone and discovering a breach that happened four months ago.

Do this instead

Event history only covers 90 days. Create a trail to S3 on day one of every account.

Oops

Storing trail logs in the same account with broad delete permissions.

Do this instead

Send them to a separate log archive account with tight bucket policies and S3 Object Lock if required.

Your mission

Play detective

~20 min

Quick check

Which question does CloudTrail answer best?

Go deeper

  1. 1Find the event for an EC2 instance you launched and see which identity did it.
  2. 2Create a trail that logs to an S3 bucket for all Regions.
  3. 3Explain how CloudTrail helps investigate a leaked access key.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge