CloudTrail Insights and Log File Integrity
Enable CloudTrail Insights to detect unusual API activity and use digest files to verify log file integrity for forensic purposes.
CloudTrail Insights and Log File Integrity is a free AWS Solutions Architect lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is CloudTrail Insights?
CloudTrail Insights is an optional feature that uses machine learning to automatically detect unusual API activity in your AWS account. It establishes a baseline of normal API call rates and write management event volumes for each API, then alerts you when activity deviates significantly from that baseline. Insights events are delivered to the same S3 bucket as your trail logs and can also trigger EventBridge rules for automated response.
Enabling CloudTrail Insights
CloudTrail Insights is enabled per trail. You can choose to detect API call rate anomalies (unusual number of write management events per second) or API error rate anomalies (unusual number of access-denied or throttling errors). Insights requires an active trail with management events enabled. AWS charges for Insights events in addition to regular trail event charges. Insights takes 24-36 hours to establish an initial baseline before it can start detecting anomalies.
# Enable CloudTrail Insights for API call rate and error rate anomalies
aws cloudtrail put-insight-selectors \
--trail-name OrgAuditTrail \
--insight-selectors \
InsightType=ApiCallRateInsight \
InsightType=ApiErrorRateInsight
# Verify insights configuration
aws cloudtrail get-insight-selectors \
--trail-name OrgAuditTrailUnderstanding Insights Events
An Insights event has a start event and an end event. The start event fires when the anomaly begins — for example, an unusual spike in TerminateInstances calls — and the end event fires when the API call rate returns to normal. Each Insights event includes the affected API, the normal baseline rate, the observed peak rate, and the duration. This helps you understand whether an anomaly was a sustained attack or a brief burst.
# Search for Insights events in the last 30 days
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventCategory,AttributeValue=insight \
--start-time $(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ) \
--query 'Events[].{Time:EventTime,Name:EventName,Source:EventSource}' \
--output tableWhat Insights Detects in Practice
Common anomalies CloudTrail Insights flags: a credential compromise where an attacker uses stolen keys to enumerate all S3 buckets at high speed, a misconfigured deployment script that loops and calls the EC2 API thousands of times, an insider threat deleting resources faster than normal, or a supply chain attack where a Lambda function suddenly makes unusual STS calls. Insights gives you a faster detection window than manually reviewing CloudTrail logs.
EventBridge Integration for Automated Response
CloudTrail Insights events are automatically delivered to Amazon EventBridge, enabling automated response. You can create an EventBridge rule that triggers a Lambda function when an Insights event is detected — for example, to send a Slack message, create a Jira ticket, or even automatically revoke the IAM user's access keys if the anomaly matches a known attack pattern. This creates a real-time security automation pipeline around Insights findings.
# EventBridge rule to trigger Lambda when a CloudTrail Insights event fires
aws events put-rule \
--name CloudTrailInsightsAlert \
--event-pattern '{
"source": ["aws.cloudtrail"],
"detail-type": ["AWS Insight via CloudTrail"]
}' \
--state ENABLED
# Add Lambda as the target
aws events put-targets \
--rule CloudTrailInsightsAlert \
--targets Id=LambdaTarget,Arn=arn:aws:lambda:us-east-1:111122223333:function:SecurityResponderLog File Integrity Validation
Log file integrity validation ensures that CloudTrail log files have not been modified, deleted, or forged after delivery to S3. When enabled (via --enable-log-file-validation), CloudTrail creates a digest file every hour that contains the SHA-256 hashes of all log files delivered during that hour, plus the hash of the previous digest. The digest file itself is signed with CloudTrail's private key. You can validate logs using the AWS CLI's validate-logs command.
# Enable log file validation when creating or updating a trail
aws cloudtrail update-trail \
--name OrgAuditTrail \
--enable-log-file-validation
# Validate log file integrity for a specific time range
aws cloudtrail validate-logs \
--trail-arn arn:aws:cloudtrail:us-east-1:111122223333:trail/OrgAuditTrail \
--start-time 2024-01-01T00:00:00Z \
--end-time 2024-01-02T00:00:00Z \
--verboseHow Digest Files Work
Every hour, CloudTrail delivers a digest file to S3 at a path separate from log files (s3://bucket/CloudTrail-Digest/...). The digest contains the SHA-256 hash of each log file delivered in the past hour, the S3 URI of each file, and a hash of the previous digest (creating a hash chain). If an attacker modifies a log file after delivery, the hash in the digest will no longer match — validation will fail and report which files were tampered with.
# View the structure of a CloudTrail digest file (JSON)
# {
# "digestStartTime": "2024-01-01T00:00:00Z",
# "digestEndTime": "2024-01-01T01:00:00Z",
# "logFiles": [
# {
# "s3Bucket": "my-cloudtrail-logs",
# "s3Object": "AWSLogs/.../CloudTrail/.../2024/01/01/file.json.gz",
# "hashValue": "sha256:abc123...",
# "hashAlgorithm": "SHA-256"
# }
# ],
# "previousDigestHashValue": "sha256:xyz789..."
# }Protecting the Audit Trail from Tampering
Log file integrity is only useful if the digest files and log files themselves are protected. Best practices: enable S3 MFA Delete on the CloudTrail bucket so files cannot be deleted without MFA, apply a deny-delete bucket policy to prevent any principal from deleting objects, enable S3 Object Lock (Compliance mode) for immutable log retention, and use an organisation trail so member accounts cannot disable logging. These controls together make it nearly impossible for an insider to erase audit evidence.
# Deny-delete policy on the CloudTrail S3 bucket
# {
# "Sid": "DenyDeleteCloudTrailLogs",
# "Effect": "Deny",
# "Principal": {"AWS": "*"},
# "Action": [
# "s3:DeleteObject",
# "s3:DeleteObjectVersion"
# ],
# "Resource": "arn:aws:s3:::my-cloudtrail-logs-111122223333/*"
# }Insights vs GuardDuty: Complementary Services
CloudTrail Insights and Amazon GuardDuty are complementary, not duplicates. Insights focuses on API call volume anomalies — sudden spikes in specific management API calls. GuardDuty analyses a broader set of data sources including CloudTrail events, VPC Flow Logs, and DNS logs to detect threat patterns such as compromised credentials, crypto mining, data exfiltration, and known malicious IPs. For defence-in-depth, enable both — Insights for volume-based anomalies, GuardDuty for threat-intelligence-based detections.
Viewing Insights in the CloudTrail Console
In the CloudTrail console, the Insights tab lists all detected anomalies with their start and end times, the API name, and a graph comparing the baseline rate vs the observed rate during the anomaly. Clicking on an Insights event links directly to the related management events in Event History for the same time window, helping you correlate 'there was an anomaly' with 'here are the specific API calls that caused it.' This drill-down capability is what makes Insights actionable.
Compliance Use Cases
Log file integrity validation is required by multiple compliance frameworks: PCI-DSS requires proof that audit logs have not been altered; HIPAA mandates tamper-evident audit controls for healthcare data; SOC 2 requires integrity controls over security logs. The combination of CloudTrail log file validation + S3 Object Lock + organisation trails satisfies these requirements and is commonly cited in AWS compliance documentation. When exam questions mention 'prove logs were not tampered with', log file integrity validation is the answer.
Quick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: CloudTrail Insights uses ML to detect unusual API call rate and error rate anomalies with start/end events, log file integrity validation uses SHA-256 digest files in a hash chain to detect any tampering or deletion of log files, and S3 Object Lock combined with deny-delete policies protects the integrity of the audit trail. Next up we explore AWS Config Rules and automated remediation.
Frequently asked questions
Is the “CloudTrail Insights and Log File Integrity” lesson free?
Yes — the full text of “CloudTrail Insights and Log File Integrity” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “CloudTrail Insights and Log File Integrity”?
Enable CloudTrail Insights to detect unusual API activity and use digest files to verify log file integrity for forensic purposes. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “CloudTrail Insights and Log File Integrity” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- CloudTrail Trails and Event History
- CloudTrail Insights and Log File Integrity
- AWS Config Rules and Remediation
- Conformance Packs and Organisation Trails