Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

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.

PieceJob
Data CatalogDatabases/tables/schemas over S3
CrawlerInfer schema from files
Glue JobETL with Spark/Ray etc.
AthenaSQL on catalog tables; pay per scan
Connect data files to a queryS3 data files: Hold the records being analysed; Glue Data Catalog: Stores schema and S3 location, not the rows; Athena: Uses metadata to query files in S3; Glue ETL job: Can read and transform selected dataS3 data filesHold the records being analysedGlue Data CatalogStores schema and S3 location, notthe rowsAthenaUses metadata to query files in S3Glue ETL jobCan read and transform selected data
The catalog describes the files. Athena queries them and Glue can transform them.

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.

  1. Store columnar Parquet/ORC, not giant CSV.
  2. Partition by a field your queries use often. For sales stored under sales/dt=2026-10-27/, register dt as a partition column and use WHERE dt = '2026-10-27'. Athena can skip the other date partitions when the query filters that partition key.
  3. Use Athena workgroups with bytes-scanned limits.
  4. SELECT only needed columns.
  5. Compress; avoid small-file explosions.
  6. 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.

  1. Create/choose an S3 prefix with a tiny CSV/Parquet sample.
  2. Run a Glue crawler or manual catalog table.
  3. Open Athena, select workgroup, run COUNT(*).
  4. Rerun with partition filter; compare data scanned.
  5. Note IAM: athena, glue, s3 list/get.

Cleanup (stop billing)

  1. Drop lab databases/tables; empty lab prefixes.
  2. 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 / symptomFix
CSV everything — huge Athena billsConvert to Parquet.
Forgot partition in WHEREAlways filter partitions.
Crawler overwrote careful schemaLock schema; use versioning.
Small files millionsCompact with Glue job.
Open workgroup no limitsSet per-query scan caps.
Public S3 lakeBlock public; bucket policies.
Glue job IAM *Scope to lab buckets.
JSON nested chaosFlatten in ETL; document schema.
Athena result bucket world-readablePrivate results bucket.
Timezone partition mistakesStore UTC; document.

8. Troubleshooting checklist

  1. ZERO RECORDS → path/partition mismatch.
  2. AccessDenied → glue:GetTable + s3:GetObject.
  3. HIVE_CANNOT_OPEN_SPLIT → bad files/compression.
  4. Crawler no-op → classify check / exclusions.
  5. Slow Glue → DPUs / worker type.
  6. 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

  1. Write two Athena queries: bad (full scan) vs good (partitioned).
  2. Convert a tiny CSV to Parquet with a local tool or Glue idea.
  3. List IAM actions Athena needs on S3 + Glue.

In short

  1. Glue catalogs and ETL; Athena SQL on S3.
  2. Parquet + partitions control cost.
  3. Workgroups limit surprise bills.
  4. 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.

Revision card: Glue + Athena. CSV dumps in S3 are not a queryable warehouse by themselves. Glue crawls/transforms data (ETL + Data Catalog). Athena runs SQL on S3 using that catalog — serverless. Crawl S3 → tables in Glue Catalog → Athena SELECT with cost controls → optional Glue job to Parquet. Analyst asks Athena for yesterday’s GMV; Glue job earlier converted raw JSON to partitioned Parquet.
Revision card: Glue + Athena · Download PNG · Open card page
Revision card: Glue Data Catalog. Without a catalog every tool reinvents schema and breaks on drift. The catalog is a Hive-compatible metastore of databases/tables/partitions pointing at S3. Use crawlers or IaC to register tables; keep schema evolution intentional. Athena, Redshift Spectrum, and EMR all see the same sales table definition.
Revision card: Glue Data Catalog · Download PNG · Open card page
Revision card: Glue ETL jobs. Raw nested JSON is expensive and slow to query repeatedly. Glue jobs (Spark/Python Shell) transform and write columnar Parquet/ORC with partitions. Partition by date/region; compress; avoid small files; schedule with Triggers or Step Functions. Daily job writes s3://lake/sales/date=2026-10-27/ as Parquet for Athena.
Revision card: Glue ETL jobs · Download PNG · Open card page
Revision card: Athena cost control. SELECT * over terabytes scans huge bytes and surprises the bill. Athena charges by data scanned. Columnar formats, partitions, and column projection cut bytes. SELECT needed columns; WHERE on partition keys; set workgroup bytes limits and alerts. Query drops from 120 GB scanned to 2 GB after Parquet + date filter.
Revision card: Athena cost control · Download PNG · Open card page
Revision card: Workgroups and governance. Everyone sharing one open Athena setup can overspend and mix result buckets. Workgroups isolate users/settings, enforce output locations, and publish metrics. Create analytics vs ad-hoc workgroups; encrypt results; IAM per workgroup. Interns use ad-hoc with 1 GB scan limit; finance uses analytics with wider limits.
Revision card: Workgroups and governance · Download PNG · Open card page
Comparison: AWS Glue ETL vs Amazon Athena. AWS Glue ETL: Jobs crawl/transform to Parquet and manage catalog. Amazon Athena: Serverless SQL over S3 using the catalog.
Comparison: AWS Glue ETL vs Amazon Athena · Download PNG · Open card page
Comparison: Amazon Athena vs Amazon Redshift. Amazon Athena: Pay per data scanned on S3; no cluster to resize. Amazon Redshift: Managed warehouse for heavy joins & concurrency.
Comparison: Amazon Athena vs Amazon Redshift · Download PNG · Open card page
Interview card: Glue vs Athena?. Glue: catalog + ETL. Athena: serverless SQL over S3 using the catalog. Together they make an S3 data lake queryable and cheaper with Parquet. Crawl → Parquet job → Athena SELECT.
Interview card: Glue vs Athena? · Download PNG · Open card page
Interview card: How does Athena billing work?. Primarily by bytes scanned per query — minimize with columns, partitions, columnar formats. Workgroup limits stop runaway SELECT *. 120GB → 2GB after Parquet + date partition filter.
Interview card: How does Athena billing work? · Download PNG · Open card page
Interview card: Why the Data Catalog?. One metastore of table/partition schemas so Athena and other engines share definitions. Stops every tool inventing its own schema. Same sales table for Athena and EMR.
Interview card: Why the Data Catalog? · Download PNG · Open card page
Interview card: Why partition Glue/Athena tables?. Partitions let queries prune S3 prefixes so Athena scans fewer bytes and Glue jobs write cheaper datasets. Pick columns used in almost every WHERE (date, region). date=2026-10-27/region=ap-south-1/ under the sales table.
Interview card: Why partition Glue/Athena tables? · Download PNG · Open card page

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.

0 of 3 answered correctly
1. Which part describes column names, types and location for files read as a table?

Answer and explanation

C. The Glue Data Catalog table metadata

The catalog tells Athena how to interpret the available files. ETL changes their physical form.

2. What lets the example skip unrelated date folders?

Answer and explanation

B. A filter on the registered partition key

Filtering by partition helps Athena avoid reading unrelated partitions.

3. Which output measures the amount read rather than the number of rows returned?

Answer and explanation

A. Bytes scanned in the Athena query statistics

A small result can still require a large scan. Check both result correctness and scan size.

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 scenario

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

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Get tables

See lake tables.

Get tables in database shivnerischool_lake.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy List workgroups

Cost controls.

List Athena workgroups.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. 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?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. 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?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. 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.

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Get table

Schema check.

Get table sales in shivnerischool_lake.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Get crawler

Infer jobs.

Get crawler shivnerischool-sales.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Get query execution

Check state/scanned.

Get query execution qid-123.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. 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/*.

  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Partition JSON

Cost feature.

JSON date 2026-10-27.

  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. 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.

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Hard Start crawler

Refresh catalog.

Start crawler shivnerischool-sales.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. 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.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. 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/*.

  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. 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.

  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.