Lesson 3 of 5 Data Transformation and Integration

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.

Scenario questions

Choose the EMR option

Exam skills 1.2.1

Choose the Amazon EMR deployment option for each team.

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

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.

OptionChoose when
AWS GlueServerless Spark ETL with catalogue integration and least management
EMR ServerlessServerless Spark with EMR runtime and versions
EMR on EC2Custom configuration, specific frameworks, long-running clusters, Spot task nodes
EMR on EKSOrganization 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.

The weekly 1.5 PB log job on EMR on EC2. A few On-Demand core nodes hold the cluster's data, many Spot task nodes do most of the processing with managed scaling, Graviton instances lower the price further, and the cluster runs the custom parsing JAR as a step and terminates when the step completes.
Node counts are illustrative.
True or false

Spark habits

Exam skills 1.2.1 · 1.1.6

Check the Spark practices that keep ML data processing fast.

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

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.

Check yourself

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.