Lesson 3 of 3 AWS CloudTrail

Analysing CloudTrail Events with Insights, Athena and EventBridge

This lesson explains how CloudTrail Insights detects unusual activity automatically, and how Athena and CloudWatch Logs make large volumes of events searchable.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe what CloudTrail Insights detects.
  • Query events with Athena, and explain CloudTrail Lake's status.
  • React to API calls in real time with EventBridge.

CloudTrail Insights

CloudTrail Insights learns the normal rate of write management API calls (API call rate insights) and of failed calls (API error rate insights) for an account, and generates an Insights event when activity deviates significantly, such as a burst of TerminateInstances calls or a sudden increase in AccessDenied errors from a misconfigured deployment. Insights events are delivered to the trail's bucket and to EventBridge, so they can trigger notifications.

Querying with Athena, CloudWatch and CloudTrail Lake

Amazon Athena queries trail log files in S3 with SQL. The CloudTrail console can create the Athena table for a trail, and partition projection on account, Region and date keeps queries fast and cheap. A trail that also sends to CloudWatch Logs supports metric filters, alarms and Logs Insights queries for recent events. CloudTrail Lake stores events in event data stores queried with SQL; it was closed to new customers on 31 May 2026, so new designs use trails with Athena or CloudWatch Logs instead, while existing customers can continue to use it.

SELECT useridentity.arn, eventname, count(*) AS calls
FROM cloudtrail_logs
WHERE errorcode = 'AccessDenied'
  AND timestamp >= '2026/10/10'
GROUP BY useridentity.arn, eventname
ORDER BY calls DESC
LIMIT 20;
Scenario questions

Where to analyse events

Exam skills 1.1.1 · 4.1.2

Choose where to analyse CloudTrail events for each need.

Log in to try this activity Interactive activities are free with an account.

Reacting to events in real time

CloudTrail management events also flow to the default EventBridge bus as events with detail-type AWS API Call via CloudTrail. An EventBridge rule can react within seconds to a specific call, such as DeleteTrail, PutBucketPolicy or CreateAccessKey, without waiting for log files. The following table compares the ways of acting on CloudTrail data.

ApproachLatencyBest for
EventBridge rule on API call eventsSecondsImmediate automated reaction to a specific API call
Metric filter and alarm on CloudWatch LogsMinutesCounting patterns and alarming on thresholds
Athena on S3 log filesMinutes to query, any historyInvestigations over months of events
CloudTrail InsightsMinutesDetecting unusual call or error rates without defining thresholds

The following diagram shows three of the approaches from the table side by side.

Four ways to act on CloudTrail data, by latency. An EventBridge rule on AWS API Call via CloudTrail events reacts to a specific call within seconds. A metric filter and alarm on the trail's log group counts patterns within minutes. Athena queries months of log files in S3, and CloudTrail Insights detects unusual call or error rates without thresholds.
The faster the approach, the narrower the question it answers: one call, a pattern count, or any history.
Put in order

Reacting to an API call

Exam skills 1.2.2 · 3.2.2

Put the steps that turn an API call into an automatic response in order.

Log in to try this activity Interactive activities are free with an account.
Worked example

Tagging new instances automatically

Finance wants every new EC2 instance tagged with the identity of the person who launched it. An EventBridge rule matches source: aws.ec2, detail-type: AWS API Call via CloudTrail and eventName: RunInstances. Its Lambda target reads detail.userIdentity.arn and the instance IDs from detail.responseElements.instancesSet and calls CreateTags with a CreatedBy tag. Because the rule is Regional, it is deployed to every Region in use with a StackSet.

Check yourself

What makes Athena queries on trail logs efficient as the bucket grows?

Show answer

Partition projection, which limits each query to the relevant partitions.

Exam Tips

Remember for the exam

  • CloudTrail Insights detects unusual API call volumes and error rates.
  • Query trail logs in S3 with Athena; use partition projection.
  • React to a specific API call in seconds with an EventBridge rule on 'AWS API Call via CloudTrail'.
  • CloudTrail Lake is closed to new customers (May 2026); prefer trails with Athena or CloudWatch Logs.