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.
| Piece | Plain job |
|---|---|
| Trail | Record API calls to S3 |
| Management events | Control-plane APIs (Create*, Put*) |
| Data events | S3 object / Lambda invoke level (costly) |
| Config recorder | Store resource configs over time |
| Config rule | Pass/fail policy check |
| Conformance pack | Bundle of rules as a unit |
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.
- Create an organization trail (or at least multi-region trail) to a central log bucket.
- Enable log file validation; restrict bucket with SCPs/policies.
- Turn on Config recorder in each region you use; deliver to bucket/topic.
- Start with managed rules: restricted-ssh, root-mfa, encrypted volumes.
- Add conformance packs for CIS/PCI-like baselines when ready.
- Subscribe SNS for NON_COMPLIANT.
- 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.
- Separate duties: trail admins ≠ app admins.
- Watch cost of data events; enable selectively.
- 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
| Service | Question it answers |
|---|---|
| CloudTrail | Who called which API when? |
| Config | What is the resource state / compliant? |
| CloudWatch | Is the system healthy/metrics/logs now? |
| GuardDuty | Does 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.
- Create a multi-region trail to a new S3 bucket with validation on.
- Enable Config recorder; deliver to the same or sibling bucket.
- Enable managed rule restricted-ssh (or equivalent).
- Create a disposable lab security group and leave it unattached. Add a temporary SSH rule from
0.0.0.0/0and check forNON_COMPLIANT. Remove the rule and confirm the next evaluation reportsCOMPLIANT. - Query CloudTrail (console Event history) for the Authorize* call.
Cleanup (stop billing)
- Close the SG; delete lab rule if desired; stop recorder only if lab-only.
- 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 / symptom | Fix |
|---|---|
| Trail only in one region | Multi-region or org trail. |
| Everyone can delete log bucket | SCPs + bucket policy deny delete. |
| Config off in secondary regions | Turn on where you deploy. |
| Ignored NON_COMPLIANT noise | Tune rules; fix or suppress with tickets. |
| Data events on all S3 forever | Selective prefixes; watch bill. |
| No encryption on log bucket | SSE-KMS + TLS. |
| Looked only at CloudWatch for “who” | Use CloudTrail for API actor. |
| Clock skew confuses timelines | Normalize to UTC in reports. |
| Shared admin IAM for trail edits | Break-glass only. |
| Never tested Athena permissions | Prep a saved query. |
10. Troubleshooting checklist
- Trail not logging: delivery errors to S3 / KMS.
- Config insufficient delivery privilege.
- Rule stuck: wait for evaluation; check scope.
- Event history delay: use S3/Athena for deep history.
- Org trail not visible in member: expected — management account.
- 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
- Write one Athena-style question you would ask after a breach.
- Name five managed Config rules useful for startups.
- Sketch who can write vs read the log bucket.
In short
- CloudTrail = who called APIs.
- Config = resource state + rules.
- Org trail + locked bucket = baseline.
- 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.








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.
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 scenarioAmravati 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.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Recorder status
Delivery health.
Describe configuration recorder status.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Describe CloudTrail trails
Audit trail list.
Describe trails.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- 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?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- 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?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Medium Describe Config rules
Compliance rules.
Describe config rules.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Get compliance details
Who fails.
Get compliance details by config rule amravatiagro-s3-encrypted.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Get trail status
Logging on?
Get trail status amravatiagro-org-trail.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Get event selectors
Data events scope.
Get event selectors for amravatiagro-org-trail.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Allow LookupEvents
Forensic LP.
Allow cloudtrail:LookupEvents on *.
- Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
- In each statement write Effect, Action and Resource.
- Give only what the task needs (least privilege).
- Use double quotes and commas correctly. Click Check answer.
Medium Recorder enabled JSON
Must be ON.
JSON recording_enabled true.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- 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?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Medium Sample delivery frequency hours
Snapshot cadence.
Sample Config snapshot hours often used (enter 24)?
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard Lookup events
Find API calls.
Lookup events.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Hard Allow GetComplianceDetails
Auditor LP.
Allow config:GetComplianceDetailsByConfigRule on *.
- Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
- In each statement write Effect, Action and Resource.
- Give only what the task needs (least privilege).
- Use double quotes and commas correctly. Click Check answer.
Hard Multi-region trail JSON
Org trail.
JSON IsMultiRegionTrail true.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.