AWS Glue and Athena: ETL and SQL on S3 Data Lakes Explained
Data lakes on S3 fill with CSV and Parquet. Someone still needs to clean columns and let analysts write SQL without a big cluster on day one. AWS Glue catalogs and transforms; Amazon Athena runs SQL directly on S3. Together they are the broom and the notebook for your lake.
In this chapter
- Why lakes need a catalog
- Glue crawlers, jobs, Data Catalog
- Athena SQL, workgroups, cost control
- Partitions and file formats
- Lab, errors, FAQ, interview
1. Everyday example first
A retail chain drops daily sales Parquet into s3://company-lake/sales/date=... Glue crawler updates the table. A business analyst runs Athena: SELECT store, sum(amount) ... WHERE date=... and pays per data scanned — so partitions matter.
2. Why Glue + Athena?
Without a catalog, every job hard-codes paths. Without serverless SQL, analysts wait for warehouses. Glue Data Catalog is the hive-style metastore; Athena queries it. Glue ETL (Spark) cleans heavy jobs when SQL alone is not enough.
3. What each piece does
Start with one sales file in S3. Its rows contain store, date and amount, but the file alone does not tell Athena how you want to query those columns. The Glue Data Catalog can describe a table with column types and a location. A crawler can help discover a schema. An ETL job can extract data, transform it into a useful layout and load the result, for example converting raw CSV to Parquet. Athena reads the table description to query the files as rows and columns. Ask which step changed the physical file and which step described it.
| Piece | Job |
|---|---|
| Data Catalog | Databases/tables/schemas over S3 |
| Crawler | Infer schema from files |
| Glue Job | ETL with Spark/Ray etc. |
| Athena | SQL on catalog tables; pay per scan |
4. How to keep costs sane
A partition groups records by a value such as date and can let Athena skip unrelated folders. Columnar Parquet groups values by column so a query can read less when it needs only a few columns. In the sample, compare a report for all dates with one that filters a known partition. Check bytes scanned and confirm the returned totals for the selected date. The number of returned rows and the amount read are different facts, so look at both when you assess the query.
- Store columnar Parquet/ORC, not giant CSV.
- Partition by a field your queries use often. For sales stored under
sales/dt=2026-10-27/, registerdtas a partition column and useWHERE dt = '2026-10-27'. Athena can skip the other date partitions when the query filters that partition key. - Use Athena workgroups with bytes-scanned limits.
- SELECT only needed columns.
- Compress; avoid small-file explosions.
- Lifecycle raw junk out of hot prefixes.
-- Athena mental model
-- SELECT store_id, SUM(amount) AS sales
-- FROM sales
-- WHERE date = '2026-10-27'
-- GROUP BY 1;
-- Partition column in WHERE → less data scanned
5. Industries
- Retail: daily sales lakes
- Adtech: click logs to Parquet
- Healthcare analytics on de-identified exports
- Finance: reconciliations on landed files
6. Lab: query sample with Athena (or paper SQL)
Use sample amounts 125 and 175 for the same store on date one, and 80 on date two. Before running the SQL, calculate the first date’s expected total of 300. Check that the query filters the registered partition and returns that value. If it returns zero, compare the path and partition metadata. If it returns 380, check whether you left out the date filter. In a sandbox remove the sample query output and objects at the end.
Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.
- Create/choose an S3 prefix with a tiny CSV/Parquet sample.
- Run a Glue crawler or manual catalog table.
- Open Athena, select workgroup, run COUNT(*).
- Rerun with partition filter; compare data scanned.
- Note IAM: athena, glue, s3 list/get.
Cleanup (stop billing)
- Drop lab databases/tables; empty lab prefixes.
- Disable crawlers on schedule.
7. Common errors and fixes
Each row is a real mistake students and juniors hit. Read the fix before you panic.
| Error / symptom | Fix |
|---|---|
| CSV everything — huge Athena bills | Convert to Parquet. |
| Forgot partition in WHERE | Always filter partitions. |
| Crawler overwrote careful schema | Lock schema; use versioning. |
| Small files millions | Compact with Glue job. |
| Open workgroup no limits | Set per-query scan caps. |
| Public S3 lake | Block public; bucket policies. |
| Glue job IAM * | Scope to lab buckets. |
| JSON nested chaos | Flatten in ETL; document schema. |
| Athena result bucket world-readable | Private results bucket. |
| Timezone partition mistakes | Store UTC; document. |
8. Troubleshooting checklist
- ZERO RECORDS → path/partition mismatch.
- AccessDenied → glue:GetTable + s3:GetObject.
- HIVE_CANNOT_OPEN_SPLIT → bad files/compression.
- Crawler no-op → classify check / exclusions.
- Slow Glue → DPUs / worker type.
- Unexpected cost → workgroup metrics.
9. FAQ
Q. Athena vs Redshift?
Athena=serverless SQL on S3; Redshift=warehouse cluster/serverless warehouse.
Q. Is Glue only Spark?
Spark common; also other engines/options over time — check current.
Q. Do I need crawlers always?
No — IaC/manual tables fine.
Q. Iceberg/ACID?
Modern table formats supported in evolving ways — verify for your region.
Q. Charge when query fails?
Failed queries can still scan — limits help.
10. Interview Q&A
Q. What is the Glue Data Catalog?
Central metastore of databases/tables for analytics.
Q. How Athena prices?
Primarily by bytes scanned per query.
Q. Why Parquet?
Columnar; reads fewer bytes for analytical SQL.
Q. What does a crawler do?
Infers schema and creates/updates tables.
Q. Partition projection?
Athena feature to avoid millions of partition objects — advanced.
Q. Lake vs warehouse?
Lake stores varied files; warehouse optimized curated schemas.
11. Tips in English, Marathi and Hindi
Ravindra Bagale's Tip (EN)
Partitions are a cost feature, not decoration. Put date filters in every habit query.
Ravindra Bagale's Tip (MR)
Partitions = cost feature. प्रत्येक query मध्ये date filter सवय.
Tip (HI)
Partitions सजावट नहीं — cost feature है; हर query में date filter डालो।
Try at home
- Write two Athena queries: bad (full scan) vs good (partitioned).
- Convert a tiny CSV to Parquet with a local tool or Glue idea.
- List IAM actions Athena needs on S3 + Glue.
In short
- Glue catalogs and ETL; Athena SQL on S3.
- Parquet + partitions control cost.
- Workgroups limit surprise bills.
- Secure the lake: no public buckets.
Revision, interview and comparison cards
Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.











More cards: Ravi Sir's Cards.
Practise this chapter
Interview questions and answers
Why can a query return the right totals and still scan more data than intended?
It may read many partitions or columns before filtering the output. Compare the table’s registered partitions and query predicate and inspect its scanned bytes. Use the same expected totals while testing a query that reads only the intended date and columns.
Check your understanding
Choose an answer, then compare your reasoning with the explanation.
Practice Tasks
Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.
About this scenarioShivneri Schools is a education business in Junnar. Kavita Shinde looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 16
Easy List Glue databases
Catalog inventory.
List Glue databases.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Get tables
See lake tables.
Get tables in database shivnerischool_lake.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy List workgroups
Cost controls.
List Athena workgroups.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Apply the lesson: scenario 4
For Athena SQL on-demand queries, reducing which quantity usually reduces query charges: scanned bytes or result rows?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Easy Apply the lesson: scenario 5
Your analytics queries read a few columns from a wide dataset. Which columnar file format taught here can replace raw CSV?
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Easy Public lake bad — 0
Block public.
Is a public S3 data lake OK? Enter 0 for no.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Get table
Schema check.
Get table sales in shivnerischool_lake.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Get crawler
Infer jobs.
Get crawler shivnerischool-sales.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Get query execution
Check state/scanned.
Get query execution qid-123.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Medium Athena results put
Result bucket write.
Allow s3:PutObject on arn:aws:s3:::shivnerischool-ath-results/*.
- Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
- In each statement write Effect, Action and Resource.
- Give only what the task needs (least privilege).
- Use double quotes and commas correctly. Click Check answer.
Medium Partition JSON
Cost feature.
JSON date 2026-10-27.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.
Medium Apply the lesson: scenario 12
A per-query scan limit is 1 GiB. How many MiB is that? Enter only the number.
- Read the situation and identify what you need to decide.
- Work through the relevant concept or calculation.
- Enter only the requested term or number.
- Check your answer, then read the explanation.
Hard Start crawler
Refresh catalog.
Start crawler shivnerischool-sales.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Hard Start query
SQL on S3.
Start query execution with string SELECT 1 and workgroup primary.
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Hard Glue read lake bucket
ETL needs GetObject.
Allow s3:GetObject on arn:aws:s3:::shivnerischool-lake/*.
- Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
- In each statement write Effect, Action and Resource.
- Give only what the task needs (least privilege).
- Use double quotes and commas correctly. Click Check answer.
Hard Query meta JSON
Always filter partitions.
JSON sql SELECT store_id FROM sales WHERE date = 2026-10-27.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.