Flytekit AWS EMR Serverless Plugin: run Spark and Hive jobs from Flyte tasks
Project description
Flytekit AWS EMR Serverless Plugin
A Flyte connector for AWS EMR Serverless that submits Spark and Hive jobs to an EMR Serverless application and tracks them through to completion.
Features
- Pythonic Spark mode: write a Flyte
@taskwhose body is regular PySpark; the plugin packages the user code, uploads it to S3, and runs it on EMR Serverless. No long-lived cluster to manage. - Script Spark mode: point at an existing
main.py(or JAR) already in S3 and submit it directly. - Hive mode: submit a Hive query (inline or from S3) against an EMR Serverless application configured for Hive.
- Async connector lifecycle (
create/get/delete) so the connector pod stays light and many jobs can be tracked concurrently. - Honours Flyte task retries, timeouts, and cancellation, and surfaces EMR Serverless logs through the Flyte UI when log URIs are available.
Installation
pip install flytekitplugins-awsemrserverless
The connector is registered automatically with flytekit via the plugin entry point. Deploy it on a flyteconnector pod that has this package installed and an IAM identity allowed to call EMR Serverless StartJobRun / GetJobRun / CancelJobRun and to read/write the script-staging S3 prefix.
Usage
Pythonic Spark task
from flytekit import task, workflow
from flytekitplugins.awsemrserverless import EMRServerless, EMRServerlessSparkJobDriver
@task(
task_config=EMRServerless(
application_id="00fhabc12345",
execution_role_arn="arn:aws:iam::123456789012:role/EMRServerlessRole",
region="us-east-1",
job_driver=EMRServerlessSparkJobDriver(
spark_submit_parameters="--conf spark.executor.cores=2 --conf spark.executor.memory=4g",
),
),
)
def spark_count() -> int:
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
return spark.range(1_000_000).count()
@workflow
def wf() -> int:
return spark_count()
The plugin serializes the task body, uploads it to S3, and EMR Serverless runs it inside the worker image you have associated with the application.
Script Spark task
@task(
task_config=EMRServerless(
application_id="00fhabc12345",
execution_role_arn="arn:aws:iam::123456789012:role/EMRServerlessRole",
region="us-east-1",
job_driver=EMRServerlessSparkJobDriver(
entry_point="s3://my-bucket/scripts/main.py",
entry_point_arguments=["--date", "2025-01-01"],
spark_submit_parameters="--conf spark.executor.memory=4g",
),
),
)
def submit_script():
...
Hive task
from flytekitplugins.awsemrserverless import EMRServerless, EMRServerlessHiveJobDriver
@task(
task_config=EMRServerless(
application_id="00fhabc12345",
execution_role_arn="arn:aws:iam::123456789012:role/EMRServerlessRole",
region="us-east-1",
job_driver=EMRServerlessHiveJobDriver(
query="SELECT COUNT(*) FROM my_table",
),
),
)
def hive_query():
...
Worker image
For Pythonic Spark tasks the worker image must contain flytekit and this plugin so the executor can rehydrate the task object on the EMR Serverless side. Script Spark and Hive jobs do not require flytekit on the worker.
A reference Dockerfile is shipped alongside this plugin; it builds on the public EMR Serverless Spark base image and installs the matching flytekit and flytekitplugins-awsemrserverless versions:
docker build \
--build-arg VERSION=<flytekit-version> \
-t <registry>/emr-serverless-flytekit:<tag> \
plugins/flytekit-aws-emr-serverless
Override the base with --build-arg EMR_BASE_IMAGE=... to track a different EMR release.
IAM
The connector pod's IAM principal needs:
emr-serverless:StartJobRun,emr-serverless:GetJobRun,emr-serverless:CancelJobRunon the target applications3:GetObject/s3:PutObjecton the script-staging prefix (Pythonic mode)iam:PassRolefor the EMR Serverless execution role
The execution role attached to the EMR Serverless application is the role the workers run as and needs whatever data-access permissions your jobs require.
Discussion
Tracking issue: flyteorg/flyte#7286.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flytekitplugins_awsemrserverless-1.16.26.tar.gz.
File metadata
- Download URL: flytekitplugins_awsemrserverless-1.16.26.tar.gz
- Upload date:
- Size: 37.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aeddc814d3accfd4bcd4a30c6845b358e124080111a06373850716bcd62cbfe
|
|
| MD5 |
eee36370e6e111a4210f2cdf5c817a7a
|
|
| BLAKE2b-256 |
bfbdbe05891c64568ce8b06bf7b3aca0f999ab085822fb735f6b2d0141a5dbcc
|
File details
Details for the file flytekitplugins_awsemrserverless-1.16.26-py3-none-any.whl.
File metadata
- Download URL: flytekitplugins_awsemrserverless-1.16.26-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07205426bd38ae48a3bb1dee734aa4243862dfe360a44410803b551ca8cf2691
|
|
| MD5 |
bbcf202520680277ca63450ed8f9cb39
|
|
| BLAKE2b-256 |
2c8633f5c2d9e668691b432ef54b548e36584cc1798ade8d707763d768eb6ed3
|