Lesson 1 of 5 Data Transformation and Integration

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.

True or false

Catalog and crawlers

Exam skills 1.2.1

Check how the Glue Data Catalog and crawlers work.

Log in to try this activity Interactive activities are free with an account.

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.

The daily churn feature job. Raw order files land hourly; the Glue job reads only new files through its bookmark, removes duplicate order IDs, aggregates orders and spend per customer over 90 days and writes Parquet that both the training pipeline and Feature Store batch ingestion read.
The prefix names are illustrative.
Match the pairs

Glue job features

Exam skills 1.2.1 · 1.1.6

Match each Glue ETL feature with the problem it solves.

Log in to try this activity Interactive activities are free with an account.

When Glue fits

The following table summarises Glue's capabilities for ML data preparation.

CapabilityML use
Crawlers and Data CatalogDiscover and query training data with Athena
Spark ETL with DynamicFramesClean, join and aggregate large datasets serverlessly
Job bookmarksIncremental processing of new data only
FindMatchesFuzzy deduplication of customer or product records
Sensitive data detectionFind and mask PII before training
Glue Data QualityRule-based checks inside the pipeline
Worked example

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.

Check yourself

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.