Lesson 1 of 6 AWS Glue

Building Serverless ETL Jobs with AWS Glue

This lesson explains how AWS Glue runs serverless Apache Spark and Python jobs for extract, transform and load (ETL), billed only while jobs run and with no clusters to manage.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish Spark, Spark Streaming and Python shell jobs.
  • Use DynamicFrames, job bookmarks and other Glue features.
  • Identify supported formats and authoring tools.
  • Monitor and troubleshoot Glue jobs.

Job types and workers

AWS Glue runs three types of job. Spark jobs, written in PySpark or Scala, spread large-scale batch ETL across many workers. Spark Streaming jobs read Kinesis or Kafka continuously and process records in small batches. Python shell jobs run a plain Python script on a single small worker, for small tasks such as calling an API or running a SQL statement, where Spark would be wasteful. The following table summarises the job types.

Job typeUse for
Spark (PySpark or Scala)Large-scale batch ETL
Spark StreamingReading Kinesis or Kafka continuously
Python shellSmall tasks that do not need Spark

The following list describes the workers on which jobs run and the related cost options.

  • Jobs run on workers measured in DPUs: general-purpose G.1X and G.2X, memory-heavy G.4X and G.8X, and small workers for streaming.
  • Auto scaling adds and removes workers during a run.
  • Flex execution runs non-urgent jobs on spare capacity at a lower price, with possibly longer start times.
  • Newer Glue versions (mapping to Spark and Python versions) start faster and perform better.
Sort into groups

Which Glue job type?

Exam skills 1.2.5

Choose the Glue job type for each task.

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

Key programming features

Several Glue features solve common ETL problems. DynamicFrames are Glue's version of Spark DataFrames that tolerate inconsistent schemas, such as a column that is sometimes a number and sometimes text; resolveChoice decides how to handle such mixed types. Job bookmarks remember which data a job has already processed, so each run handles only new files or rows, which makes incremental processing simple.

Pushdown predicates filter by partition before reading, so a job reads only the partitions it needs. groupFiles combines many small input files into larger groups, which avoids the overhead of processing each tiny file separately. The hashfield and hashpartitions options split a JDBC read across workers, so a large database table is read in parallel. The following table summarises the features.

FeatureWhat it does
DynamicFramesHandle inconsistent schemas; resolveChoice fixes mixed types
Job bookmarksRemember what was processed, so each run handles only new data
Pushdown predicatesRead only the partitions needed
groupFilesCombine many small input files
hashfield, hashpartitionsParallelise JDBC reads
Match the pairs

Glue programming features

Exam skills 1.2.5 · 1.4.1

Match each problem with the Glue feature that solves it.

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

Formats and authoring

AWS Glue jobs read and write the common data lake formats, namely CSV, JSON, Parquet, ORC and Avro, and support the open table formats Apache Iceberg, Apache Hudi and Delta Lake, which add upserts, deletes and time travel to lake tables.

Jobs can be authored in several ways. AWS Glue Studio provides a visual editor in which sources, transformations and targets are connected as a diagram, and it generates the job's code, which suits common transformations and teams less familiar with Spark. Developers can instead write scripts directly, or develop interactively in notebooks. Glue connections let jobs reach JDBC databases inside a VPC and software-as-a-service sources.

True or false

Formats and authoring

Exam skills 1.2.5 · 1.2.6

Decide whether each statement about Glue jobs is true.

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

Monitoring and troubleshooting

Glue offers several views into a job: the history of job runs, CloudWatch job metrics, observability metrics that reveal skew and memory pressure across workers, continuous logging while a job runs, and the Spark UI, which shows each stage and task. Three problems account for most failures and slow jobs. Out-of-memory errors mean a worker ran out of memory, fixed with larger or more workers. Data skew means a few workers receive far more data than others, because some key values are very common; repartitioning or salting the key spreads the work. Many small files slow every stage, fixed by compacting them or reading with groupFiles. The following table summarises the fixes.

ProblemFix
Out-of-memory errorsLarger or more workers
Data skewRepartitioning or salting
Many small filesCompaction or groupFiles

The following diagram shows how run time changes once the job reads only new data.

The nightly CSV-to-Parquet job before and after the fixes. Without bookmarks, each run reads every file in the bucket, so run time grows every night. With job bookmarks and a pushdown predicate on the date partition, each run reads only the new day, so run time stays flat; Flex execution and auto scaling lower the cost of each run.
The run times are illustrative.
Match the pairs

Fixing Glue jobs

Exam skills 1.2.7 · 3.3.6

Match each Glue job problem with its fix.

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

A nightly job that reprocesses everything

A Glue job converting daily CSV files to Parquet takes longer every night, because it reads every file in the bucket, including all previous days.

FixEffect
Enable job bookmarksThe job processes only files added since its last successful run
Use a push-down predicate on the date partitionReads only the needed partitions from the catalogue
Use Flex execution for this non-urgent jobLower cost per DPU-hour
Enable auto scaling of workersUses only the workers each run needs

Run time drops from hours to minutes and stays flat as data accumulates. If the job ever needs to reprocess history, the bookmark can be reset for that run.

Check yourself

Which Glue feature lowers the cost of jobs that are not urgent?

Show answer

Flex execution, which runs jobs on spare capacity at a lower price, with less predictable start times.

Exam Tips

Remember for the exam

  • To process only new data on each run, use job bookmarks.
  • For cheaper non-urgent jobs, use Flex execution.
  • Out-of-memory errors call for a larger worker type (G.2X or above) or repartitioning.
  • To read only the partitions you need, use pushdown predicates.
  • With many small input files, use groupFiles or compact them first.
  • For upserts and time travel in the lake, use Iceberg, Hudi or Delta Lake with Glue.