Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Config and CloudTrail: Compliance and API Audit Logs Explained

When something breaks in production, the first questions are: who changed what, and is the account still compliant? AWS CloudTrail records API activity. AWS Config records how resources look over time and evaluates rules. Together they are your CCTV + inspector for the cloud.

What you'll learn in this chapter

  • Why audit and config history matter
  • What CloudTrail trails and Config recorders/rules are
  • How to turn on org-ready logging and queries
  • Industries and compliance mapping
  • Lab, errors, FAQ, interview

1. Everyday example first

A Jaipur SaaS admin finds a security group wide open. CloudTrail shows which IAM user called AuthorizeSecurityGroupIngress at 14:02. Config rule restricted-ssh is NON_COMPLIANT and SNS already paged the on-call. Without both, you only guess.

2. Why Config and CloudTrail?

Why do we need this?

Security, finance, and customers ask for evidence. Trail answers “who API-called what”. Config answers “what did the resource look like and does it match policy”.

  • Investigate incidents with API history
  • Prove compliance with rules and conformance packs
  • Detect drift from approved architecture
  • Feed SIEM / Athena / Lake Formation analytics

3. What each service does

What is it?

CloudTrail: management events (and optionally data events) to S3/CloudWatch Logs. Organization trail covers all accounts. Config: configuration recorder + delivery channel to S3; rules (managed/custom) evaluate compliance continuously or on change.

PiecePlain job
TrailRecord API calls to S3
Management eventsControl-plane APIs (Create*, Put*)
Data eventsS3 object / Lambda invoke level (costly)
Config recorderStore resource configs over time
Config rulePass/fail policy check
Conformance packBundle of rules as a unit
API call → CloudTrail log | Resource change → Config item → RuleChange happens
Evidence + compliance status

4. How to turn on a solid baseline

How to do it (step by step)

  1. Create an organization trail (or at least multi-region trail) to a central log bucket.
  2. Enable log file validation; restrict bucket with SCPs/policies.
  3. Turn on Config recorder in each region you use; deliver to bucket/topic.
  4. Start with managed rules: restricted-ssh, root-mfa, encrypted volumes.
  5. Add conformance packs for CIS/PCI-like baselines when ready.
  6. Subscribe SNS for NON_COMPLIANT.
  7. Use Athena or CloudTrail Lake to query “who deleted the DB”.
  8. Separate duties: trail admins ≠ app admins.
  9. Watch cost of data events; enable selectively.
  10. Document retention (e.g., 7 years finance) with lifecycle.
# Athena mindset
# SELECT useridentity.arn, eventname, eventtime
# FROM cloudtrail_logs
# WHERE eventname = '''AuthorizeSecurityGroupIngress'''
# LIMIT 20;

5. Config vs CloudTrail vs CloudWatch

ServiceQuestion it answers
CloudTrailWho called which API when?
ConfigWhat is the resource state / compliant?
CloudWatchIs the system healthy/metrics/logs now?
GuardDutyDoes this activity look malicious?

6. Multi-industry notes

Banks keep org trails in a locked security account. Hospitals map Config rules to access logging for PHI-adjacent systems. Ecommerce uses Athena to find which key opened an S3 dump during a blip.

7. Industries and roles

  • Security teams: incident forensics
  • FinOps: who launched huge instances
  • Auditors: evidence packs
  • DevOps: drift after Terraform apply
  • Gov: mandatory logging retention

8. Lab: trail + one Config rule

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  1. Create a multi-region trail to a new S3 bucket with validation on.
  2. Enable Config recorder; deliver to the same or sibling bucket.
  3. Enable managed rule restricted-ssh (or equivalent).
  4. Open SSH from 0.0.0.0/0 on a lab SG; wait for NON_COMPLIANT.
  5. Query CloudTrail (console Event history) for the Authorize* call.

Cleanup (stop billing)

  1. Close the SG; delete lab rule if desired; stop recorder only if lab-only.
  2. Empty/delete lab buckets carefully after you finish.

9. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
Trail only in one regionMulti-region or org trail.
Everyone can delete log bucketSCPs + bucket policy deny delete.
Config off in secondary regionsTurn on where you deploy.
Ignored NON_COMPLIANT noiseTune rules; fix or suppress with tickets.
Data events on all S3 foreverSelective prefixes; watch bill.
No encryption on log bucketSSE-KMS + TLS.
Looked only at CloudWatch for “who”Use CloudTrail for API actor.
Clock skew confuses timelinesNormalize to UTC in reports.
Shared admin IAM for trail editsBreak-glass only.
Never tested Athena permissionsPrep a saved query.

10. Troubleshooting checklist

  1. Trail not logging: delivery errors to S3 / KMS.
  2. Config insufficient delivery privilege.
  3. Rule stuck: wait for evaluation; check scope.
  4. Event history delay: use S3/Athena for deep history.
  5. Org trail not visible in member: expected — management account.
  6. Huge bill: disable unused data events.

11. FAQ

Q. CloudTrail free?

Management events free tier style historically; storage costs — verify pricing.

Q. Replace SIEM?

Trail feeds SIEM; not a full SIEM alone.

Q. Config vs Terraform state?

Config is AWS truth; state is tool memory.

Q. Latency of events?

Near real time; not instant atomic.

Q. Conformance pack?

Deploy many rules as one package.

Q. CloudTrail Lake?

Managed querying/store option for trails.

12. Interview Q&A

Q. CloudTrail purpose?

Account API activity audit log.

Q. Config purpose?

Resource configuration history + compliance rules.

Q. Org trail?

One trail covering all member accounts.

Q. Management vs data events?

Control plane vs data plane (S3/Lambda…).

Q. NON_COMPLIANT next step?

Alert, ticket, remediate or justify.

Q. Why both services?

Actor history + resource state/compliance.

13. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Turn on org CloudTrail before you need it. Forensics cannot invent yesterday’s API calls.

Ravindra Bagale's Tip (MR)

Org CloudTrail गरज पडण्याआधी चालू करा. कालची API नंतर invent होत नाही.

Tip (HI)

जरूरत से पहले org CloudTrail ऑन करो — कल की API बाद में बनाई नहीं जा सकती।

Try at home

  1. Write one Athena-style question you would ask after a breach.
  2. Name five managed Config rules useful for startups.
  3. Sketch who can write vs read the log bucket.

In short

  1. CloudTrail = who called APIs.
  2. Config = resource state + rules.
  3. Org trail + locked bucket = baseline.
  4. Alert on NON_COMPLIANT and practice queries.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: Config and CloudTrail. You cannot prove compliance or who changed prod without records. AWS Config records resource state and rules. CloudTrail records API activity (who/what/when). Enable multi-region trail + org trail; turn on Config recorder; attach managed rules. “Who made the bucket public?” → CloudTrail. “Is encryption on?” → Config rule.
Revision card: Config and CloudTrail · Download PNG · Open card page
Revision card: Use them together. Config without Trail misses actors; Trail without Config misses ongoing drift. Trail answers who changed; Config answers what is true now and whether it stays compliant. Alarm on noncompliant rules; protect Trail log bucket; enable log file validation. SG opens 22 → Config NON_COMPLIANT; Trail shows the IAM user that authorized it.
Revision card: Use them together · Download PNG · Open card page
Comparison: AWS Config vs AWS CloudTrail. AWS Config: Resource configuration history and compliance rules. AWS CloudTrail: API activity: who did what when.
Comparison: AWS Config vs AWS CloudTrail · Download PNG · Open card page
Comparison: Config managed rule vs Manual spreadsheet audit. Config managed rule: Auto evaluates resources continuously. Manual spreadsheet audit: Humans sample rows and miss drift.
Comparison: Config managed rule vs Manual spreadsheet audit · Download PNG · Open card page
Interview card: Config vs CloudTrail roles?. Config = resource configuration & compliance over time; CloudTrail = API who/what/when. You usually need both for security reviews. Public bucket: Trail=who; Config=still public?.
Interview card: Config vs CloudTrail roles? · Download PNG · Open card page
Interview card: What is a Config rule?. A managed or custom check that marks resources COMPLIANT or NON_COMPLIANT. Remediate with SSM Automation or tickets. s3-bucket-server-side-encryption-enabled rule.
Interview card: What is a Config rule? · Download PNG · Open card page
Interview card: Why multi-region trail?. API calls happen in every region; a single-region trail misses others. Org trail covers member accounts. Attacker uses ap-southeast-1; multi-region trail still logs.
Interview card: Why multi-region trail? · Download PNG · Open card page
Interview card: Why log file validation?. Detects tampering of delivered Trail digests/logs. Pair with locked/MFA-delete log bucket. Validation fails → investigate integrity incident.
Interview card: Why log file validation? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

Amravati Agro Market is a agriculture business in Amravati. Anjali Thakre looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Describe Config recorder

Why: Is recording on?

What to do: Describe configuration recorders.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Recorder status

Why: Delivery health.

What to do: Describe configuration recorder status.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Describe CloudTrail trails

Why: Audit trail list.

What to do: Describe trails.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Config detects drift — 1

Why: Compliance.

What to do: Enter 1 if Config detects resource drift.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy CloudTrail answers who — 1

Why: Audit.

What to do: Enter 1 if CloudTrail answers who did what.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Describe Config rules

Why: Compliance rules.

What to do: Describe config rules.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Get compliance details

Why: Who fails.

What to do: Get compliance details by config rule amravatiagro-s3-encrypted.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Get trail status

Why: Logging on?

What to do: Get trail status amravatiagro-org-trail.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Get event selectors

Why: Data events scope.

What to do: Get event selectors for amravatiagro-org-trail.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Allow LookupEvents

Why: Forensic LP.

What to do: Allow cloudtrail:LookupEvents on *.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Recorder enabled JSON

Why: Must be ON.

What to do: JSON recording_enabled true.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Medium Log file validation — 1

Why: Integrity.

What to do: Enter 1 if enable log file validation.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Sample delivery frequency hours

Why: Snapshot cadence.

What to do: Sample Config snapshot hours often used (enter 24)?

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Lookup events

Why: Find API calls.

What to do: Lookup events.

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard Allow GetComplianceDetails

Why: Auditor LP.

What to do: Allow config:GetComplianceDetailsByConfigRule on *.

How:
  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Hard Multi-region trail JSON

Why: Org trail.

What to do: JSON IsMultiRegionTrail true.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.