Querying S3 Logs with Athena
Understand how serverless SQL searches logs without a database.
Querying S3 Logs with Athena is a free AWS Security Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Amazon Athena Is
Amazon Athena is a serverless, interactive query service that runs standard SQL directly against data stored in Amazon S3. There is no database to provision or manage: you point Athena at data in S3, define a schema, and query. This makes it ideal for analyzing the huge log files AWS produces.
Serverless and Pay-Per-Query
Athena is serverless and you pay per query based on the amount of data scanned. There is no idle cost when you are not querying. This pricing model rewards efficient queries and well-organized data, since scanning less data is both faster and cheaper, a theme that recurs throughout Athena usage.
Why Athena for Security Logs
Security generates mountains of logs: CloudTrail, VPC Flow Logs, ALB access logs, and more, all landing in S3. Athena lets you investigate them with familiar SQL instead of building a data pipeline. During an incident you can search months of history across billions of records in minutes, which is exactly what investigations demand.
Schema-on-Read
Athena uses schema-on-read: you define a table schema that describes how to interpret files in S3, and the schema is applied when you query, not when data is stored. The raw log files are never modified. This means you can layer new tables and views over the same untouched logs at any time.
The Role of the Data Catalog
Athena reads table definitions from the AWS Glue Data Catalog, a central metadata store. A table maps a location in S3 plus a format to columns and types. Once cataloged, the table is available to Athena and other analytics services, giving you one shared definition of your log data.
Supported Formats
Athena queries many formats: JSON, CSV, Apache Parquet, ORC, and Avro. CloudTrail logs are JSON and Flow Logs are space-delimited text. Columnar formats like Parquet are far more efficient because Athena reads only the columns a query needs, scanning less data and cutting cost.
Running a Query
You run queries in the Athena console, the API, or the CLI, and results are written to an S3 query results location. A simple investigative query might count failed console logins by user. Athena returns results in seconds to minutes depending on data volume, with no infrastructure to manage.
SELECT useridentity.username, COUNT(*) AS attempts
FROM cloudtrail_logs
WHERE eventname = 'ConsoleLogin'
AND errormessage = 'Failed authentication'
GROUP BY useridentity.usernameSecuring Athena Access
Athena access is governed by IAM policies, and queries can only read S3 data the caller is permitted to access. You should also encrypt the query results location, since results may contain sensitive log content. Workgroups let you separate teams, enforce result encryption, and set per-query data-scan limits.
Federated Queries
Beyond S3, Athena federated queries can reach other data sources like DynamoDB or RDS through connectors. While most security log analysis targets S3, federation lets you join log data with reference data, such as an asset inventory, to enrich an investigation without moving everything into S3 first.
Workgroups for Governance
Workgroups isolate queries, results, and settings for different teams. A workgroup can enforce an encrypted results location, set a separate query results bucket, and cap the bytes a single query may scan. This both contains cost and keeps one team's sensitive investigation results separate from another's.
When to Reach for Athena
Use Athena when you need to analyze large volumes of historical logs ad hoc, especially CloudTrail and Flow Logs in S3. For real-time alerting you still rely on CloudWatch and GuardDuty; Athena is the deep-dive tool for after-the-fact investigation and reporting across massive datasets.
Quick Check
Test your Athena fundamentals.
Recap
Amazon Athena runs SQL directly on S3 data, serverless and priced by data scanned. It uses schema-on-read with table definitions in the Glue Data Catalog and supports formats like JSON and efficient Parquet. Secure it with IAM, encrypted results locations, and workgroups. It is the go-to tool for deep, after-the-fact analysis of CloudTrail and Flow Logs.
Frequently asked questions
Is the “Querying S3 Logs with Athena” lesson free?
Yes — the full text of “Querying S3 Logs with Athena” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “Querying S3 Logs with Athena”?
Understand how serverless SQL searches logs without a database. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Security Academy?
No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Querying S3 Logs with Athena” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Security Academy lesson?
Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Querying S3 Logs with Athena
- Building Tables Over CloudTrail Data
- Investigating Incidents with SQL Queries
- Partitioning Logs for Speed and Cost