CloudTrail and AWS Config
Overview
AWS CloudTrail answers "who did what, when and from where?" by recording API calls made in your account. AWS Config answers "what does my resource look like now, how has it changed, and does it comply with my rules?" Together they are the audit backbone of AWS operations.
Picture a building: CloudTrail is the door-access log (who entered which room), while Config is the inventory photographed daily (what changed in each room and whether it breaks policy).
SysOps administrators use them for incident forensics ("who deleted that security group?"), compliance reporting and automatic remediation.
Key Concepts
- CloudTrail Event history shows the last 90 days of management events for free, per Region; create a trail for longer retention to S3.
- Management events (control plane) are logged by default; data events (S3 objects, Lambda invoke, DynamoDB items) and Insights events are optional and billed.
- A trail can be multi-Region and organisation-wide; enable log file validation (digest files) to detect tampering.
- CloudTrail Lake stores events in a managed event data store and supports SQL queries.
- AWS Config records configuration items and relationships and keeps a timeline per resource.
- Config rules (managed or custom Lambda/Guard) evaluate compliance continuously or on change; conformance packs bundle rules.
- Remediation actions run SSM Automation documents on non-compliant resources; aggregators collect data across accounts and Regions.
- Config does not prevent actions; it detects and remediates. Prevention is IAM / SCP.
Detailed Notes
CloudTrail vs Config
| Question | Tool |
|---|---|
Who called DeleteSecurityGroup at 14:03? | CloudTrail |
| What were the SG rules last Tuesday? | Config timeline |
| Are all EBS volumes encrypted? | Config rule |
| Which IP made the failed console login? | CloudTrail |
| Alert when root user signs in | CloudTrail + EventBridge/CloudWatch |
Creating an organisation trail
aws cloudtrail create-trail --name org-trail --s3-bucket-name my-trail-bucket \
--is-multi-region-trail --is-organization-trail --enable-log-file-validation \
--kms-key-id alias/trail-key
aws cloudtrail start-logging --name org-trail
aws cloudtrail put-event-selectors --trail-name org-trail --advanced-event-selectors file://sel.json
The destination bucket needs a policy allowing cloudtrail.amazonaws.com to put objects. Deliver to CloudWatch Logs too if you want metric filters and alarms (for example, alarm on ConsoleLogin without MFA or on DeleteTrail).
Finding who did something
aws cloudtrail lookup-events --lookup-attributes \
AttributeKey=EventName,AttributeValue=TerminateInstances --max-results 5
Typical CloudTrail Lake query:
SELECT eventTime, userIdentity.arn, sourceIPAddress, eventName
FROM <event-data-store-id>
WHERE eventName = 'DeleteBucket' AND eventTime > '2025-01-01 00:00:00'
AWS Config setup
aws configservice put-configuration-recorder --configuration-recorder name=default,roleARN=arn:aws:iam::111122223333:role/ConfigRole \
--recording-group allSupported=true,includeGlobalResourceTypes=true
aws configservice put-delivery-channel --delivery-channel name=default,s3BucketName=my-config-bucket
aws configservice start-configuration-recorder --configuration-recorder-name default
aws configservice put-config-rule --config-rule file://encrypted-volumes.json
Rule example (managed): ENCRYPTED_VOLUMES, S3_BUCKET_PUBLIC_READ_PROHIBITED, RESTRICTED_INCOMING_TRAFFIC, REQUIRED_TAGS, ROOT_ACCOUNT_MFA_ENABLED.
Auto-remediation with Config
aws configservice put-remediation-configurations --remediation-configurations '[{
"ConfigRuleName":"s3-bucket-public-read-prohibited",
"TargetType":"SSM_DOCUMENT","TargetId":"AWS-DisableS3BucketPublicReadWrite",
"Automatic":true,"MaximumAutomaticAttempts":3,"RetryAttemptSeconds":60,
"Parameters":{"AutomationAssumeRole":{"StaticValue":{"Values":["arn:aws:iam::111122223333:role/ConfigRemediation"]}},
"S3BucketName":{"ResourceValue":{"Value":"RESOURCE_ID"}}}}]'
Multi-account views
- Config aggregator: read-only view of compliance across accounts/Regions (via Organizations).
- Conformance packs: deploy sets of rules and remediation as one template across the organisation.
- Advanced queries use SQL against current configuration state.
Troubleshooting
| Symptom | Cause |
|---|---|
| Config shows nothing for a resource type | Recorder not recording that type, or recorder stopped |
| Trail log files missing | Bucket policy or KMS key policy blocks CloudTrail |
| Data events not visible | Not enabled; they are off by default |
| Cannot see event from other Region | Trail is single-Region; use multi-Region trail |
| Capability | What it gives you | Operational tip |
|---|---|---|
| CloudTrail Lake | Managed event data store with SQL queries, up to 7 years retention | Replaces hand-built Athena tables for investigations |
| Log file integrity validation | SHA-256 digest files prove logs were not altered | aws cloudtrail validate-logs |
| Organization trail | One trail for every account, created from the management or delegated administrator account | Members cannot disable it |
| Insights events | Detects unusual API call rates or error rates | Extra cost; enable on write-management events |
| Config aggregator | Single view of configuration and compliance across accounts and Regions | Needs authorization or Organizations integration |
| Conformance packs | Bundle of Config rules and remediation deployed as one unit | Deploy by YAML template, org-wide |
aws cloudtrail validate-logs --trail-arn arn:aws:cloudtrail:us-east-1:111122223333:trail/org-trail --start-time 2025-01-01T00:00:00Z
aws cloudtrail start-query --query-statement "SELECT eventName, userIdentity.arn, eventTime FROM <store-id> WHERE eventName = 'DeleteBucket' ORDER BY eventTime DESC LIMIT 20"
aws configservice put-remediation-configurations --remediation-configurations file://remediation.json
aws configservice select-resource-config --expression "SELECT resourceId WHERE resourceType = 'AWS::EC2::Instance' AND configuration.instanceType = 't2.micro'"
Remember the division of labour: CloudTrail answers "who did what and when", Config answers "what did it look like and is it compliant", and CloudWatch answers "how is it performing now". Config rules are either detective (evaluate and report) or paired with automatic remediation through SSM Automation; Config records configuration items, not data-plane traffic.
Real World Example
Scenario – who opened port 22? During a security review, a Config rule reports a production security group open to the world. The team opens the Config timeline to see exactly when the rule appeared, then queries CloudTrail for the AuthorizeSecurityGroupIngress call at that time, identifying the IAM role and source IP.
They then enable an automatic remediation that revokes such rules, add an SCP to deny the action outside a break-glass role, and set up a CloudWatch alarm on that API call for the future.
Architecture Diagram
- 1Users and services call AWS APIs.
- 2CloudTrail records each call and delivers it to S3 and CloudWatch Logs.
- 3Config records resulting configuration changes and evaluates rules.
- 4Non-compliance triggers alarms or SSM remediation, with CloudTrail as evidence.
Best Practices
- ✓Create an organisation, multi-Region trail with log file validation, KMS encryption and a locked-down bucket in a log-archive account.
- ✓Send CloudTrail to CloudWatch Logs and alarm on root login, IAM policy changes and trail changes.
- ✓Enable Config in all Regions and use aggregators for central compliance views.
- ✓Deploy conformance packs for baseline controls and attach automatic remediation carefully.
- ✓Enable data events only where needed (sensitive buckets) because of volume and cost.
Common Interview Questions
Exam Tips
SOA-C03 focus
- "Who made the change" -> CloudTrail. "What changed / is it compliant" -> Config.
- Event history is 90 days; longer retention requires a trail to S3 or CloudTrail Lake.
- S3 object-level or Lambda invoke auditing -> data events (not on by default).
- Config detects and remediates; to prevent an action use IAM/SCP.
Chapter quiz
Monitoring, Logging and Observability · 10 questions
1.An operations team needs to alert when memory utilisation on EC2 instances exceeds 85%. What must they do FIRST?
2.Which solution turns the number of ERROR lines in an application log group into an alarm?
3.A security group was modified and an auditor asks which IAM principal made the change and from which IP address. Which service provides this?
4.A company wants every non-compliant security group that allows 0.0.0.0/0 on port 22 to be fixed automatically. Which approach has the LEAST operational overhead?
5.An EventBridge scheduled rule must start a job at 02:00 in the America/New_York time zone including daylight saving changes. What should be used?
6.An alarm must page the team only when both p99 latency and the 5xx error rate are high, to reduce noise from single-metric blips. What should the engineer create?
7.Custom application memory usage is missing from CloudWatch for EC2 instances. What is the standard fix?
8.A team stores 3 years of application logs in a CloudWatch log group and the bill keeps growing. Logs older than 30 days are never queried. What is the most cost-effective action?
9.Security wants an immutable record proving CloudTrail logs have not been tampered with. Which feature provides this?
10.An EventBridge rule matches events (MatchedEvents is greater than zero) but the Lambda target is never executed. What is the most likely cause?
0 of 10 answered
Finished this lesson?
0 of 46 lessons done · 0% of the course

