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

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.

What you'll learn 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?

Why do we need this?

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

What is 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
S3 files → Crawler/Catalog → Athena SQL / Glue ETLRaw files need answers
Catalog then query or transform

4. How to keep costs sane

How to do it (step by step)

  1. Store columnar Parquet/ORC, not giant CSV.
  2. Partition by date (and careful other keys).
  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)

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  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.

Practice Tasks

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

Why: Catalog inventory.

What to do: List Glue databases.

How:
  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

Why: See lake tables.

What to do: Get tables in database shivnerischool_lake.

How:
  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

Why: Cost controls.

What to do: List Athena workgroups.

How:
  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 Athena bills by scan — 1

Why: Bytes scanned.

What to do: Enter 1 if Athena primarily bills by data scanned.

How:
  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.

Easy Prefer Parquet — 1

Why: Columnar.

What to do: Enter 1 if Parquet is preferred over giant CSV for Athena.

How:
  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.

Easy Public lake bad — 0

Why: Block public.

What to do: Is a public S3 data lake OK? Enter 0 for no.

How:
  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

Why: Schema check.

What to do: Get table sales in shivnerischool_lake.

How:
  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

Why: Infer jobs.

What to do: Get crawler shivnerischool-sales.

How:
  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

Why: Check state/scanned.

What to do: Get query execution qid-123.

How:
  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

Why: Result bucket write.

What to do: Allow s3:PutObject on arn:aws:s3:::shivnerischool-ath-results/*.

How:
  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

Why: Cost feature.

What to do: JSON date 2026-10-27.

How:
  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 Workgroup limit GB sample

Why: Cap surprise bills.

What to do: Sample workgroup scan limit in GB for labs (enter 1)?

How:
  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.

Hard Start crawler

Why: Refresh catalog.

What to do: Start crawler shivnerischool-sales.

How:
  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

Why: SQL on S3.

What to do: Start query execution with string SELECT 1 and workgroup primary.

How:
  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

Why: ETL needs GetObject.

What to do: Allow s3:GetObject on arn:aws:s3:::shivnerischool-lake/*.

How:
  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

Why: Always filter partitions.

What to do: JSON sql SELECT store_id FROM sales WHERE date = 2026-10-27.

How:
  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.