Amazon Athena
Athena as serverless SQL on data in S3, its pricing, how columnar formats, compression and partitions cut cost and time, and federated queries across other data sources.
What it is
Amazon Athena is a serverless query service that analyses data stored in Amazon S3 with standard SQL.
- There's nothing to load or provision: a table is defined over files in S3, then queried.
- Supports CSV, JSON, ORC, Avro, Parquet (and more, such as logs and Amazon Ion).
- Query results are written to S3.
- Pricing: $5 per TB of data scanned (10 MB minimum per query). DDL statements and failed queries are free.
- Commonly used with QuickSight for reports and dashboards, and with the Glue Data Catalog for table definitions.
- Athena can also run Apache Spark code in notebooks.
Use cases: business intelligence, ad-hoc analysis and reporting; querying VPC Flow Logs, ELB logs, CloudTrail trails, S3 access logs and other AWS logs.
Updated since the slides
The slides say Athena is built on Presto. Today's engine (engine version 3) is built on Trino, the successor project to Presto, with improvements from both. For the exam this changes nothing: Athena is serverless SQL on S3.
Performance and cost
Billing is for the data scanned, so scanning less is both faster and cheaper:
- Use columnar data (Apache Parquet or ORC). A query reads only the columns it needs: a huge performance gain and a big saving. Use Glue to convert the data to Parquet or ORC.
- Compress the data for smaller reads (Snappy, gzip, zstd, LZ4, bzip2…).
- Partition datasets in S3, so queries filter on virtual columns and skip whole folders:
s3://bucket/table/<column>=<value>/<column>=<value>/…- for example
s3://athena-examples/flight/parquet/year=1991/month=1/day=1/
- Use larger files (over about 128 MB) to cut overhead. Many small files slow queries down.
For example, a 3 TB CSV file costs $15 per full scan. Compressed 3:1 with gzip, it costs $5. Stored as Parquet, a query that reads one of four columns scans only about 0.25 TB: $1.25.
Federated query
Athena Federated Query runs SQL across data stored in relational, non-relational, object and custom data sources, in AWS or on premises.
- It uses data source connectors, which run on AWS Lambda, to read each source (CloudWatch Logs, DynamoDB, RDS, Redshift, DocumentDB, ElastiCache, HBase on EMR, on-premises databases over JDBC…).
- A single query can join data from several sources.
- Store the results back in S3.
Since April 2026, some newly created connectors are registered in the Glue Data Catalog and no longer need a Lambda function in the customer's account. The exam idea stays the same: connectors let Athena query data outside S3.
Real-world examples
- A security team queries six months of VPC Flow Logs in S3 to find every connection to a suspicious IP address, paying only for the data scanned.
- A retailer converts daily CSV sales files to Parquet, partitioned by date, and its dashboards query only the last week: cost drops by more than 90%.
- An analyst joins customer orders in DynamoDB with product data in Aurora in one Athena query, with federated query.
Exam tips
- "Analyse data in S3 using serverless SQL" → Athena.
- "Query VPC Flow Logs, ELB logs, CloudTrail logs ad hoc" → Athena.
- "Reduce Athena cost or improve performance" → columnar formats (Parquet, ORC), compression, partitioning, larger files.
- "Run SQL across DynamoDB, RDS and on-premises data without moving it" → Athena Federated Query.
- "Dashboards on Athena results" → QuickSight.
Common traps
- "Athena needs a cluster" or "load the data into Athena first." It's serverless and queries files in place.
- "Pay per hour." Athena charges per TB scanned (unless capacity reservations are bought).
- "Partitioning by every column." Too many small partitions and files make queries slower.
Hands-on lab: query a CSV file with Athena
Goal: create a table over a CSV file in S3 and query it.
Costs money
Athena charges $5 per TB scanned with a 10 MB minimum per query, so ten test queries cost about $0.0005. S3 storage for a tiny file is a fraction of a cent. Any Region works.
Upload the data
Create a bucket saa-athena-<your-initials> with folders data/ and results/. Upload a file data/sales.csv:
region,product,amount
eu,shoes,120
us,shoes,80
eu,hats,45Point Athena at the results folder
Open Athena → Query editor → Settings → Manage and set the query result location to s3://saa-athena-<your-initials>/results/.
Create the table
Run:
CREATE EXTERNAL TABLE sales (region string, product string, amount int)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION 's3://saa-athena-<your-initials>/data/'
TBLPROPERTIES ('skip.header.line.count'='1');Query it
Run SELECT region, SUM(amount) FROM sales GROUP BY region;. Look at Data scanned under the results.
Expected result: eu 165 and us 80, with a few bytes scanned (billed as 10 MB).
Clean up: run DROP TABLE sales;, then empty and delete the bucket.
AWS documentation
Analytics
The map of AWS analytics services, from ingesting and storing data to preparing, querying and visualizing it, and which service answers which exam question.
Amazon Redshift
Redshift as the AWS data warehouse, its leader and compute nodes, provisioned and serverless modes, Multi-AZ, snapshots and cross-Region DR, loading data, zero-ETL, and Redshift Spectrum.