Preparing ML Datasets with AWS Glue
This lesson explains AWS Glue, the serverless data integration service most often used to prepare large ML datasets, which combines a metadata catalogue, crawlers and Apache Spark ETL jobs without clusters to manage.
Learning outcomes
After completing this lesson, you will be able to:
- Catalog data with the Glue Data Catalog and crawlers.
- Write Glue ETL jobs with DynamicFrames and job bookmarks.
- Decide when Glue fits ML data preparation.
Glue Data Catalog and crawlers
Machine learning teams spend much of their time finding and understanding data. The AWS Glue Data Catalog is a central metadata store that records each table's columns, types, partitions and S3 location, and Amazon Athena, Glue jobs, Amazon EMR and SageMaker AI tools all share it, so a dataset defined once can be used by every tool.
Crawlers populate the catalogue automatically: they scan S3 prefixes or JDBC databases, infer schemas and create or update tables and partitions. Once a dataset is catalogued, it can be queried with SQL in Athena immediately, which makes it quick to explore data, check distributions and validate candidate features before writing any transformation code.
Catalog and crawlers
Glue ETL jobs
Glue ETL jobs run PySpark or Scala Spark code, or Python shell scripts for small tasks. Glue extends Spark with DynamicFrames, which tolerate inconsistent schemas, and adds built-in transforms such as ApplyMapping, ResolveChoice, Relationalize (flattens nested JSON) and FindMatches (ML-based fuzzy deduplication). Job bookmarks process only new data on each run, and worker types (G.1X, G.2X and larger) with auto scaling set capacity. Glue Studio builds jobs visually and generates the code.
For ML, Glue jobs typically clean raw data, join sources, compute aggregate features and write partitioned Parquet that training jobs, Athena and Feature Store batch ingestion consume. Glue also provides sensitive data detection to find and mask PII during ETL and Glue Data Quality rules to validate data within the job.
The following diagram shows a daily Glue job that builds churn features from hourly order files, and the two consumers that read its output.

Glue job features
When Glue fits
The following table summarises Glue's capabilities for ML data preparation.
| Capability | ML use |
|---|---|
| Crawlers and Data Catalog | Discover and query training data with Athena |
| Spark ETL with DynamicFrames | Clean, join and aggregate large datasets serverlessly |
| Job bookmarks | Incremental processing of new data only |
| FindMatches | Fuzzy deduplication of customer or product records |
| Sensitive data detection | Find and mask PII before training |
| Glue Data Quality | Rule-based checks inside the pipeline |
A daily feature job
Raw order files land in S3 every hour. A churn model needs, per customer, the number of orders and total spend in the last 90 days, refreshed daily, with duplicates removed.
# Glue PySpark job (simplified)
orders = glueContext.create_dynamic_frame.from_catalog(
database="sales", table_name="orders_raw",
transformation_ctx="orders") # bookmark key: only new files
df = orders.toDF().dropDuplicates(["order_id"])
features = (df.filter("order_date >= date_sub(current_date(), 90)")
.groupBy("customer_id")
.agg(F.count("*").alias("orders_90d"), F.sum("amount").alias("spend_90d")))
features.write.mode("overwrite").parquet("s3://ml-features/churn/daily/")The job runs on a schedule with no cluster to manage, deduplicates on order_id and writes Parquet that both the training pipeline and a Feature Store ingestion step can read. EMR would also work but adds cluster management that this workload does not need.
Which Glue feature removes fuzzy duplicate records, such as the same customer spelled differently?
Show answer
The FindMatches ML transform.
Exam Tips
Remember for the exam
- Serverless Spark ETL for ML datasets: AWS Glue.
- Process only new files: job bookmarks.
- Fuzzy deduplication of records: Glue FindMatches.
- Find and mask PII in ETL: Glue sensitive data detection.
- Crawlers make S3 data queryable in Athena.