# CloudTrail in CloudWatch Logs Insights: who did what

Logs Insights queries · Updated 16 November 2026

**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.

## 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](https://cloudconsole.dev/how-to/find-who-stopped-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 CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Sending events to CloudWatch Logs](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/send-cloudtrail-events-to-cloudwatch-logs.html)
- [CloudWatch Logs Insights query syntax](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html)

## Related

- [How to check who stopped an EC2 instance in CloudTrail](https://cloudconsole.dev/how-to/find-who-stopped-ec2-instance)
- [How to find who deleted a resource in AWS](https://cloudconsole.dev/how-to/find-who-deleted-aws-resource)
- [ThrottlingException: Rate exceeded](https://cloudconsole.dev/errors/throttlingexception-rate-exceeded)
- [UnauthorizedOperation: You are not authorized to perform this operation. Encoded authorization failure message](https://cloudconsole.dev/errors/unauthorizedoperation-encoded-message)
- [CloudWatch Logs Insights query examples](https://cloudconsole.dev/logs-insights/query-examples)
- [API Gateway 5xx errors with Logs Insights](https://cloudconsole.dev/logs-insights/api-gateway-5xx-errors)

---

Source: https://cloudconsole.dev/logs-insights/cloudtrail-who-did-what

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
