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

AWS Cloud

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.

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?

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

Walk through one change. A test administrator authorizes a rule on a security group at 11:00. CloudTrail can record the API call, time and identity. AWS Config can record how the resource’s properties changed and evaluate whether they satisfy a selected rule. CloudWatch can show a metric or log about how the application behaved around that time. If someone asks who changed the rule, start at the recorded action. If they ask what is allowed now, inspect configuration. Keep the resource ID and Region in all three notes so they refer to the same thing.

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
Two different views of account activityCloudTrail: Records supported API activity; AWS Config: Records supported resource configuration; Config rules: Evaluate configuration against a rule; Investigation: Correlate actor, time and state changeCloudTrailRecords supported API activityAWS ConfigRecords supported resourceconfigurationConfig rulesEvaluate configuration against a ruleInvestigationCorrelate actor, time and statechange
Evidence + compliance status

4. How to turn on a solid baseline

Define the evidence your team needs before collecting it. A trail can deliver selected records over time, while Event history shows recent management events in a particular account and Region. A Config recorder stores supported resource configuration changes. A rule can turn those observations into a compliance result. Test an isolated configuration change and verify the timestamp and matching resource ID on both records. It may take time for a new evaluation to appear, so wait for the result or inspect collection status before assuming it passed.

  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 CloudTrail Event history for a recent management event in the right Region, such as a DB deletion. For older events, query the trail’s S3 logs with Athena. Existing CloudTrail Lake customers can query there. AWS closed CloudTrail Lake to new customers on May 31, 2026.
  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

Use only an unattached lab security group. Record its ID and the exact time of the rule change. Verify the CloudTrail entry names the action and actor. Verify the Config rule shows the expected noncompliant result, then revert your rule and wait for the compliant result. The lesson is complete when you can match the region, timestamp and group in both views. Delete the lab group and retain any shared settings.

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

  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. Create a disposable lab security group and leave it unattached. Add a temporary SSH rule from 0.0.0.0/0 and check for NON_COMPLIANT. Remove the rule and confirm the next evaluation reports 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?

Event history is available at no additional charge for 90 days of regional management events. Storage, data events and additional features can incur charges.

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.

Practise this chapter

Interview questions and answers

Which service answers “who authorized SSH access” versus “is the current rule compliant”?

CloudTrail can identify the actor, action, time and account for the API call. AWS Config can record the resource’s configuration and evaluate the compliance rule. Correlate the resource ID and Region so the two observations describe the same security group.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Which CloudTrail view can help find a recent regional management API call?

Answer and explanation

C. Event history

Event history provides recent management records in the selected account and Region.

2. What result tells you the security-group configuration passed an AWS Config rule?

Answer and explanation

A. COMPLIANT from that rule’s evaluation

Config rules produce evaluations for the resource settings. CloudTrail records API activity.

3. What is the safer training target for a temporary permissive security-group rule?

Answer and explanation

A. An unattached disposable security group

An unattached group can demonstrate the rule evaluation without opening access to a running workload.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

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

Is recording on?

Describe configuration recorders.

  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

Delivery health.

Describe configuration recorder status.

  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

Audit trail list.

Describe trails.

  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 Apply the lesson: scenario 4

Which service records AWS resource configuration history and evaluates configuration rules: AWS Config or CloudTrail?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Easy Apply the lesson: scenario 5

You need the caller identity and API action associated with a security-group change. Which AWS service's event records do you inspect?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Medium Describe Config rules

Compliance rules.

Describe config rules.

  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

Who fails.

Get compliance details by config rule amravatiagro-s3-encrypted.

  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

Logging on?

Get trail status amravatiagro-org-trail.

  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

Data events scope.

Get event selectors for amravatiagro-org-trail.

  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

Forensic LP.

Allow cloudtrail:LookupEvents on *.

  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

Must be ON.

JSON recording_enabled true.

  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 Apply the lesson: scenario 12

CloudTrail log-file validation helps detect whether delivered logs were changed. Does it primarily check integrity or prevent every deletion?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Medium Sample delivery frequency hours

Snapshot cadence.

Sample Config snapshot hours often used (enter 24)?

  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

Find API calls.

Lookup events.

  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

Auditor LP.

Allow config:GetComplianceDetailsByConfigRule on *.

  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

Org trail.

JSON IsMultiRegionTrail true.

  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.