CloudConsole

CloudTrail in CloudWatch Logs Insights: who did what

Updated 16 November 2026 · How we write and check guides

Short answer

If your trail delivers to CloudWatch Logs, each API call is a JSON event whose fields (eventName, eventSource, userIdentity.arn, sourceIPAddress, errorCode, requestParameters) are discovered automatically. Filter by eventName and the resource ID to see who made a change, from where and when.

Logs Insights query: filter eventSource = "ec2.amazonaws.com" and eventName in …; result columns eventTime, eventName…
The query from this page and the shape of the table it returns. Copy the query from the text below.

The query: who stopped this instance?

filter eventSource = "ec2.amazonaws.com"
  and eventName in ["StopInstances", "TerminateInstances", "RebootInstances"]
  and requestParameters.instancesSet.items.0.instanceId = "i-0123456789abcdef0"
| fields eventTime, eventName, userIdentity.arn, userIdentity.type, sourceIPAddress, userAgent, errorCode
| sort eventTime desc

Select the log group your trail writes to (for example aws-cloudtrail-logs-123456789012) and a range covering when the instance stopped.

Line by line

  1. eventSource identifies the service; eventName the API action. Filtering on both is precise and cheap to read.
  2. requestParameters.instancesSet.items.0.instanceId is the first instance ID in the request. CloudTrail records EC2's instance list as an array, which Logs Insights flattens with an index. A call that stopped several instances lists the others at .1, .2 and so on; to catch those too, use filter @message like "i-0123456789abcdef0" instead.
  3. userIdentity.arn is the caller. For an assumed role, it's the role session ARN, which often ends in the user's name or the automation's session name.
  4. sourceIPAddress and userAgent tell you whether it came from the console, the CLI, an SDK or an AWS service acting for someone.
  5. errorCode is empty for successful calls; a value such as Client.UnauthorizedOperation means someone tried and failed.

Variations

Who deleted something, across services:

filter eventName like /^Delete/ and not ispresent(errorCode)
| stats count(*) as deletes by userIdentity.arn, eventSource, eventName
| sort deletes desc

Throttled calls, to find the client hammering an API:

filter errorCode in ["ThrottlingException", "Throttling", "RequestLimitExceeded"]
| stats count(*) as throttled by eventSource, eventName, userIdentity.arn
| sort throttled desc

Access denied, useful when an automation suddenly breaks:

filter errorCode like /AccessDenied|UnauthorizedOperation/
| fields eventTime, userIdentity.arn, eventName, errorMessage
| sort eventTime desc
| limit 50

Console sign-ins:

filter eventName = "ConsoleLogin"
| fields eventTime, userIdentity.arn, sourceIPAddress, responseElements.ConsoleLogin, additionalEventData.MFAUsed
| sort eventTime desc

If your trail doesn't go to CloudWatch Logs

Logs Insights only sees CloudTrail if a trail is configured to deliver to a log group. Without that, you still have options:

  • CloudTrail Event history in the console, or aws cloudtrail lookup-events, covers the last 90 days of management events in a region, with simple attribute filters. See find who stopped an EC2 instance.
  • CloudTrail Lake or Athena over the trail's S3 bucket for SQL queries over longer history.
  • EventBridge rules matching the AWS API Call via CloudTrail detail type, to react to specific calls as they happen rather than search afterwards.

Limits and cost

CloudTrail log groups grow quickly in busy accounts, especially with data events enabled, and queries are billed by GB scanned. Filter on eventSource and eventName early and keep the time range tight. Events reach CloudWatch Logs a few minutes after the call, so a change made seconds ago may not show yet. For standing alerts on sensitive calls, a metric filter with an alarm is cheaper than repeated queries.

Questions

How do I check who stopped an EC2 instance in CloudTrail?

Search for StopInstances events with that instance ID, in CloudTrail Event history or with Logs Insights if your trail delivers to CloudWatch Logs; userIdentity.arn shows who called it.

How do I find ThrottlingException errors in CloudTrail?

Filter on errorCode values such as ThrottlingException or RequestLimitExceeded and group by eventName and userIdentity.arn to find the caller.

What is 'AWS API Call via CloudTrail' in EventBridge?

The detail type for EventBridge events generated from CloudTrail-recorded API calls, used to trigger rules on specific actions.

When this happens away from your desk

'Who changed this?' is usually asked while something is broken. CloudConsole, a phone app for AWS, is built to show alarms, resources and recent activity on your phone.

About the app → · Download on the App Store

Sources