Lesson 2 of 8 Amazon Athena and Data Analysis

Running Interactive Spark Analysis with Athena for Apache Spark

This lesson explains how Athena for Apache Spark runs PySpark and Spark SQL interactively in notebooks with no cluster to create, for analysis that is easier to express in code than in SQL.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe Spark-enabled workgroups and notebooks.
  • Choose between Athena SQL, Athena for Spark, Glue and EMR.
  • Identify typical uses of Athena for Apache Spark.

How it works

Athena for Apache Spark runs in Spark-enabled workgroups, which are separate from SQL workgroups. Users write PySpark or Spark SQL in notebooks, either in the Athena console or in Amazon SageMaker Unified Studio, and run cells interactively, seeing results immediately.

Sessions start in seconds because Athena keeps Spark capacity ready, so there is no cluster to create, size or shut down. Billing is per DPU-hour for the time a session runs, so an idle notebook should be stopped. Notebooks read tables from the AWS Glue Data Catalog, including Apache Iceberg tables, and AWS Lake Formation permissions apply, so users see only the data they are allowed to see, just as they would in Athena SQL.

True or false

Athena for Apache Spark

Exam skills 3.2.4

Decide whether each statement about Athena for Apache Spark is true.

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

Choosing an engine

Several services run SQL or Spark on lake data, and the choice depends on the work. Athena SQL is the simplest way to run ad hoc SQL over S3, with nothing to provision. Athena for Apache Spark starts Spark sessions in about a second from a notebook, which suits interactive PySpark exploration without infrastructure. Scheduled production ETL in Spark is better run as AWS Glue jobs or on EMR Serverless, which add job management, retries and scheduling. EMR on EC2 is the choice when the team needs full control of Spark versions and configuration. The following table summarises the choice.

NeedChoose
Ad hoc SQL over S3Athena SQL
Interactive PySpark exploration with no infrastructureAthena for Apache Spark
Scheduled production ETL in SparkAWS Glue or EMR Serverless
Full control of Spark versions and configurationEMR on EC2

The following diagram matches each need to an engine.

Choosing an engine for lake data. Ad hoc SQL over S3 suits Athena SQL; interactive PySpark exploration with no infrastructure suits Athena for Apache Spark; scheduled production Spark ETL suits AWS Glue or EMR Serverless; and full control of Spark versions and configuration needs EMR on EC2.
Several engines can read the same Data Catalog tables.
Sort into groups

Which engine?

Exam skills 3.2.4 · 1.2.5

Choose the engine for each need.

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

Typical uses

Athena for Apache Spark suits data scientists and engineers exploring data before building a pipeline. Typical tasks include profiling a new dataset to understand its columns, values and quality; prototyping transformations that would be awkward in SQL, such as parsing nested JSON or applying custom logic; and using Python libraries, for example for statistics or plotting.

Once the logic is settled, it usually moves out of the notebook into a scheduled AWS Glue or Amazon EMR job, which adds job management, retries, scheduling and monitoring that interactive sessions lack. The notebook remains useful for investigating problems later.

Worked example

Exploring a new dataset with PySpark

A data scientist must explore a new 500 GB dataset of device events, try several feature calculations, and use a Python library for statistics, before anything is productionised. In a Spark-enabled Athena workgroup, the notebook runs code such as the following.

df = spark.table("curated.device_events").where("event_date >= '2026-09-01'")
daily = df.groupBy("device_id", "event_date").count()
daily.describe().show()

The session starts in seconds with no cluster, and the team pays only for the DPU-hours used. Once the feature logic is settled, it moves into a scheduled Glue job.

Check yourself

Where should scheduled production Spark ETL run instead of Athena for Apache Spark?

Show answer

In AWS Glue or EMR Serverless. Athena for Apache Spark suits interactive work.

Exam Tips

Remember for the exam

  • For interactive PySpark without clusters, use Athena for Apache Spark.
  • Athena for Apache Spark runs in Spark-enabled workgroups and is billed per DPU-hour.
  • Scheduled production Spark ETL belongs in Glue or EMR Serverless.
  • Athena Spark notebooks read tables from the Glue Data Catalog.
  • Lake Formation permissions apply to Athena Spark sessions.