Processing ML Data with Apache Spark on Amazon EMR
This lesson explains when Amazon EMR, which runs open-source big data frameworks such as Apache Spark, is chosen over Glue: for control over the cluster, specific framework versions or very large, long-running processing.
Learning outcomes
After completing this lesson, you will be able to:
- Choose between EMR on EC2, EMR on EKS and EMR Serverless.
- Use Spark for distributed feature computation.
- Decide when EMR is preferable to Glue.
Deployment options
EMR offers three ways to run Spark. EMR on EC2 creates clusters of primary, core and task nodes, with full control of instance types, configuration and installed libraries. EMR on EKS runs Spark jobs on an existing Kubernetes cluster. EMR Serverless runs Spark and Hive jobs without clusters, scaling workers automatically and charging only while jobs run.
Cost controls include Spot Instances for task nodes (which hold no HDFS data, so interruptions do not lose data), managed scaling and Graviton instances. EMR can read and write S3 through EMRFS and the Glue Data Catalog as its metastore.
Choose the EMR option
Spark for ML data processing
Spark distributes DataFrame operations across executors. For ML, Spark computes features over billions of rows, joins large tables, samples data and writes Parquet. Spark MLlib provides transformers such as StandardScaler, OneHotEncoder and Bucketizer, and classic algorithms, although model training usually moves to SageMaker AI. SageMaker AI processing jobs can also run Spark through a prebuilt Spark container, and SageMaker Studio notebooks can connect to EMR clusters interactively.
The following table compares the Spark options for ML preparation.
| Option | Choose when |
|---|---|
| AWS Glue | Serverless Spark ETL with catalogue integration and least management |
| EMR Serverless | Serverless Spark with EMR runtime and versions |
| EMR on EC2 | Custom configuration, specific frameworks, long-running clusters, Spot task nodes |
| EMR on EKS | Organization standardises on Kubernetes |
| SageMaker processing (Spark container) | Spark step inside a SageMaker AI pipeline |
The following diagram shows the make-up and life cycle of an EMR on EC2 cluster that processes 1.5 PB of logs each week.

Spark habits
Petabyte log processing
A media company needs to turn 1.5 PB of viewing logs into per-user features each week. The job runs for about six hours, uses a custom JAR for log parsing and must be as cheap as possible.
An EMR on EC2 cluster with a small number of On-Demand core nodes and many Spot task nodes, managed scaling and Graviton instances, fits: it supports the custom JAR, the long run and large Spot savings. The cluster terminates after the step completes. Glue could run the job, but the custom library and the scale make EMR's control and Spot pricing the more cost-effective choice.
Which EMR option runs Spark with the EMR runtime but without clusters to manage?
Show answer
EMR Serverless.
Exam Tips
Remember for the exam
- Full control of Spark clusters and frameworks: EMR on EC2.
- Spark without clusters but with EMR runtime: EMR Serverless.
- Lower cost: Spot task nodes and managed scaling.
- Spark step in an ML pipeline: SageMaker processing job with the Spark container.
- Least management for standard ETL: Glue.