- Create a CloudTrail trail that writes logs to S3
- Inspect CloudTrail objects in the S3 console
- Auto-create an Athena external table for CloudTrail JSON
- Configure Athena query results (S3)
- Run SQL queries to analyze CloudTrail events
- AWS account with permissions to create CloudTrail trails, S3 buckets, and Athena workgroups
- Basic knowledge of SQL for simple SELECT queries
1) Create a CloudTrail trail and S3 delivery
- Open the CloudTrail console in the AWS Console. CloudTrail records API activity in your AWS account and can deliver logs to S3 for long-term storage and analysis.
- Create a new trail and give it a name (in this demo the default name remains
management-events1). Configure the trail to store logs in the CloudTrail S3 bucket. The console shows the target S3 bucket where CloudTrail will deliver logs.

- Click Create trail. After creation, the trail appears in the list with its Region, name (for example,
management-events1), and the S3 bucket created for CloudTrail logs. Example ARN for the trail (single-line format):
- Open the target S3 bucket in a new tab to verify CloudTrail’s delivery location. Newly-created trails may take a short time before objects appear.
2) Inspect the CloudTrail S3 bucket
In the S3 console you’ll find the bucket CloudTrail created for log storage. CloudTrail writes logs under a prefix similar toAWSLogs/<account-id>/CloudTrail/.

CloudTrail/ folder then your account ID and subsequent CloudTrail log folders. Immediately after creation, logs may not yet be present until API events occur.

3) Create an Athena table for CloudTrail JSON logs
CloudTrail provides an Event history helper in the console which can generate and create an Athena table for you. That helper builds aCREATE EXTERNAL TABLE statement mapped to the S3 prefix where CloudTrail writes JSON events.
When CloudTrail creates the table for you, the console shows a success message.

CREATE EXTERNAL TABLE for CloudTrail logs looks like this (the helper fills in the exact table name and S3 location for your account):
- The
LOCATIONvalue points to the S3 prefix containing CloudTrail JSON files. - The
JsonSerDeallows Athena to deserialize the JSON event records.
4) Configure Athena query result location
Before running queries in the Athena Query Editor you must configure a query result location — an S3 bucket where Athena writes query output and metadata.Do not use your CloudTrail logs bucket as the Athena query results bucket. Keep query results in a separate S3 bucket (standard storage class) to avoid accidental tampering and unnecessary access patterns.
- Open Query settings (Manage).
- Set an S3 bucket for query results (choose a separate standard S3 bucket).
- Save settings and open the Query Editor.
Athena pricing is based on the amount of data scanned per query. To reduce costs, restrict scanned data using partitioned tables,
LIMIT, WHERE filters, or by compressing and converting your logs to columnar formats like Parquet.5) Run SQL queries against the CloudTrail table
Open the Athena Query Editor and run SQL queries against your CloudTrail table. A simple example to inspect recent activity:- Click Run to execute the query.
- Athena displays query status, data scanned, runtime, and the results.
- The output shows when events occurred, the API action names, and the IAM identity ARN that performed the action.

Quick reference and best practices
Useful links:
Summary:
- Create a CloudTrail trail that delivers logs to an S3 bucket.
- Verify the S3 delivery location and objects.
- Use CloudTrail’s helper to create an Athena external table or hand-craft the CREATE statement.
- Configure Athena query results in a separate S3 bucket.
- Run SQL queries in Athena to analyze CloudTrail events and monitor API activity.