Sub topic 4
Searching recent activity with Event history
This chapter assumes you can read a CloudTrail event record (the previous chapter) and know the difference between management, data, and Insights events. You should also be comfortable running AWS CLI commands and filtering JSON output.
Event history is the fastest way to answer "who changed this?" in an AWS account. It needs no setup and costs nothing. It also has hard limits, and knowing them tells you when to stop searching and set up a trail instead.
What Event history is
Event history is a built-in, searchable record of recent management events. These are control-plane actions such as RunInstances, PutBucketPolicy, AttachUserPolicy, and StopLogging.
- It is turned on in every account by default. You cannot disable or delete it.
- It covers the last 90 days.
- It holds management events only. Data events (for example S3
GetObject) and Insights events are never in it. - It is scoped to a single Region. A search in
eu-west-1does not show what happened inus-east-1. - It is read-only. You can search and download results, but you cannot change or extend the retention.
Events usually appear within a few minutes of the API call, not instantly. If you search seconds after an action and find nothing, wait and try again.
A trail, covered in the next chapter, is a separate configuration that copies events to an S3 bucket so you keep them as long as you choose. Event history does not need a trail, and a trail does not change what Event history shows.
Searching in the console
In the CloudTrail console, choose Event history and pick a lookup attribute from the filter menu. Set a time range, and expand a row to see the full JSON record. This works well for one-off questions and for browsing. The CLI is better when you need to repeat a search, search several Regions, or process the results.
Searching with lookup-events
The CLI command is aws cloudtrail lookup-events. Here is the basic form from the plan:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=StopLogging \
--max-results 10This returns up to 10 StopLogging events from the current Region in the last 90 days. Each item in Events has a few top-level fields (EventId, EventName, EventTime, Username, EventSource, Resources, and others). It also has a CloudTrailEvent field, which holds the complete event record as a JSON string.
Lookup attributes
You can filter on exactly one of these attributes per call.
| AttributeKey | Use it to find |
|---|---|
| `EventName` | A specific API action, such as `DeleteBucket` |
| `Username` | Actions by a user name or role session name |
| `AccessKeyId` | Everything done with one access key, useful for a leaked key |
| `ResourceName` | Actions on one resource, by the name or ID the service records |
| `ResourceType` | Actions on a type of resource, such as `AWS::S3::Bucket` |
| `EventSource` | Everything for one service, such as `iam.amazonaws.com` |
| `ReadOnly` | Only reads (`true`) or only changes (`false`) |
| `EventId` | One known event |
Narrowing by time and by change
Combine one attribute with --start-time and --end-time. Using ReadOnly=false is a quick way to see only actions that changed something:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=ReadOnly,AttributeValue=false \
--start-time 2026-11-20T00:00:00Z \
--end-time 2026-11-21T00:00:00Z \
--query 'Events[].{time:EventTime,user:Username,event:EventName,source:EventSource}' \
--output tableThe --query option is a client-side JMESPath expression. It only reshapes output and does not reduce what the API returns, so it does not help with throttling or paging.
Reading the full record
The top-level fields do not include the source IP, user agent, request parameters, or error code. Those are inside CloudTrailEvent. Extract that string and parse it with jq:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=StopLogging \
--max-results 1 \
--query 'Events[0].CloudTrailEvent' \
--output text \
| jq '{who: .userIdentity.arn, when: .eventTime, from: .sourceIPAddress, agent: .userAgent, target: .requestParameters, error: .errorCode}'For the sample event in the plan, this prints Alice's ARN, the time 2026-11-20T09:15:42Z, the IP 203.0.113.10, the aws-cli/2.x agent, and the trail name org-audit-trail. If the call had failed, errorCode would hold the reason, such as AccessDenied. If it is null, the call succeeded.
Pagination and throttling
lookup-events returns at most 50 events per page, then a NextToken. The AWS CLI follows tokens automatically when you do not pass --max-results. Use --max-items to cap the total number of events returned across pages.
The API is rate limited to about two requests per second per account per Region. A script that loops quickly can get ThrottlingException. Keep calls sequential, and add a short sleep between pages if you page by hand.
Gotchas
One Region at a time
Event history only shows events from the Region you query. To search every Region, loop over them:
for r in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
echo "== $r"
aws cloudtrail lookup-events \
--region "$r" \
--lookup-attributes AttributeKey=EventName,AttributeValue=StopLogging \
--query 'Events[].[EventTime,Username,EventName]' \
--output text
donedescribe-regions lists the Regions enabled for your account. An attacker often works in a Region you never use, so a search in your home Region alone can give false comfort.
Global service events
Some services have a single global endpoint. IAM is the main example, and its events are recorded in us-east-1. If you cannot find a CreateAccessKey or AttachUserPolicy event, query us-east-1 before concluding it did not happen. Sign-in and STS events are recorded in the Region of the endpoint that was used, so they can appear in a Region you did not expect.
Username is not always a person
For an IAM user, Username is the user name. For a role, it is the session name chosen by whoever assumed the role. Many automated callers use generic names, and a person can pick any name when they call AssumeRole. For a trustworthy identity, read userIdentity in the full record. For assumed roles it includes the role ARN and the session issuer.
ResourceName must match what the service logged
ResourceName filters on the value in the event's resources field. Some services put a name there and others put an ID or full ARN. If a search by ARN returns nothing, try the short name or ID. Failing that, filter by EventName and inspect the results.
One attribute at a time
You cannot pass two lookup attributes. To combine conditions, such as "this user and this event name", filter by the more selective one and finish the job with --query or jq.
What Event history cannot answer
- Who read an S3 object, invoked a Lambda function, or accessed a DynamoDB item: these are data events.
- What happened 91 or more days ago.
- Anything in bulk, in a durable archive, or joined with other data. For those you need a trail with S3 delivery, or CloudTrail Lake.
A worked search
Suppose a colleague says a trail named org-audit-trail stopped recording sometime last week.
- Search
us-east-1and your other active Regions forEventName=StopLoggingwithin the last 90 days. - Pick the matching event and parse
CloudTrailEventwithjq. - Read
userIdentity.arnfor the actor,sourceIPAddressanduserAgentfor where it came from,requestParameters.namefor the target, anderrorCodefor the outcome. - Search again with
AttributeKey=UsernameorAttributeKey=AccessKeyId, using the values you just found, to see what else the same identity did around that time.
Step 4 is what turns a single event into a timeline, and the final chapter builds on it.
Exercise
You run aws cloudtrail lookup-events for EventName=CreateAccessKey in eu-west-1 and get no results, but you are sure an IAM user created an access key yesterday. Give two reasons the event might not be in your results, and say how you would check each.
Show answer
First, IAM is a global service and its events are recorded in us-east-1, so repeat the search with --region us-east-1. Second, the key may have been created in a different Region's endpoint context, or the event may not have been delivered yet. Loop over all enabled Regions, and if the action just happened, wait a few minutes and search again. (Also confirm the action happened within the last 90 days.)
Exercise
A role session made a change, and Username shows deploy-bot. Why should you not conclude that a person or system named deploy-bot is the real identity, and where in the event do you look instead?
Show answer
For assumed roles, Username is the session name, which the caller picks when assuming the role, so it can be generic or arbitrary. Read userIdentity in the CloudTrailEvent JSON, which contains the role ARN and session context, to identify who actually assumed the role.
Exercise
Which command shows only changes (not reads) made on 2026-11-20, as a table of time, user, and event name?
Show answer
aws cloudtrail lookup-events --lookup-attributes AttributeKey=ReadOnly,AttributeValue=false --start-time 2026-11-20T00:00:00Z --end-time 2026-11-21T00:00:00Z --query 'Events[].{time:EventTime,user:Username,event:EventName}' --output table