In the docker runner mode the user guide's way of giving an EMR
Serverless job run its Python libraries did nothing. "Building a Python
virtual environment" packs a virtualenv into an archive in S3 and
submits the job with:
--conf spark.archives=s3://.../pyspark_venv.tar.gz#environment
--conf spark.emr-serverless.driverEnv.PYSPARK_DRIVER_PYTHON=./environment/bin/python
--conf spark.emr-serverless.driverEnv.PYSPARK_PYTHON=./environment/bin/python
--conf spark.executorEnv.PYSPARK_PYTHON=./environment/bin/python
Floci set no driverEnv variable on the driver's container, and Spark in
local mode unpacks spark.archives into a temporary files folder of its
own once the driver's Python has started, not into the working
directory. With the variables set, the driver could not start: "Cannot
run program "./environment/bin/python"".
Now:
- a spark.emr-serverless.driverEnv.<KEY> property ("Option that adds
environment variables to the Spark driver"), from the run's
spark-defaults or a --conf in its sparkSubmitParameters, which wins,
is an environment variable of the driver's container, replacing one
of Floci's own of that name;
- each archive of spark.archives (which spark-submit's own --archives
sets, winning over a --conf, as in Spark) in Floci's S3 is read as the
run's account, streamed into the created container and unpacked into
its working directory before spark-submit starts, under the name after
its # or else its file's name, as Spark's Utils.unpack does it (.jar
and .zip unzipped, .tar.gz, .tgz and .tar untarred, anything else
copied). The guide's venv-pack example puts the environment in
/home/hadoop/environment, and /home/hadoop is the image's working
directory. An archive that cannot be read fails the run before its
driver starts, naming it; a cancel, a reset or a shutdown while they
are put in ends the copy and puts in no other.
SparkJobRunner.Job carries the archives, which classic EMR's steps
leave empty. Spark still unpacks each archive into its own files folder
too, where SparkFiles.get finds it, and gives spark.executorEnv
variables to the Python workers it starts, so those need nothing more.
19 KiB
EMR Serverless
EMR Serverless is an AWS service that provides serverless data analytics environments. Floci provides an emulator for the management-plane API (REST JSON) which covers the lifecycle of an Application and of the job runs submitted to it.
Configuration
| Key | Description | Default |
|---|---|---|
floci.emrserverless.enabled |
Whether the EMR Serverless API is enabled | true |
floci.emrserverless.port |
The port the service is exposed on | 4566 |
floci.services.emrserverless.job-run-duration-seconds |
How long a BATCH job run stays RUNNING before it succeeds; 0 makes it SUCCESS as soon as it starts |
0 |
floci.services.emrserverless.runner-mode |
immediate moves job runs through their states without running anything; docker runs each Spark job run in a container (see Running Spark job runs) |
immediate |
floci.services.emrserverless.docker-network |
Docker network for job run containers | the global default |
floci.services.emrserverless.image-template |
Image for a docker job run whose application names no custom image, %s standing for the release label |
public.ecr.aws/emr-serverless/spark/%s:latest, or spark4/ in place of spark/ for an emr-spark-* release |
floci.services.emrserverless.reconcile-containers-on-startup |
Remove the drivers a previous run of this Floci left on the Docker daemon before the first job run starts; turn it off when two Floci instances share a daemon with the same port and no resource namespace | true |
Endpoints
The emulator implements the standard AWS emr-serverless service endpoints:
POST /applications(CreateApplication)GET /applications(ListApplications)GET /applications/{applicationId}(GetApplication)PATCH /applications/{applicationId}(UpdateApplication)DELETE /applications/{applicationId}(DeleteApplication)POST /applications/{applicationId}/start(StartApplication)POST /applications/{applicationId}/stop(StopApplication)POST /applications/{applicationId}/jobruns(StartJobRun)GET /applications/{applicationId}/jobruns(ListJobRuns)GET /applications/{applicationId}/jobruns/{jobRunId}(GetJobRun)DELETE /applications/{applicationId}/jobruns/{jobRunId}(CancelJobRun)GET /applications/{applicationId}/jobruns/{jobRunId}/attempts(ListJobRunAttempts)POST /tags/{resourceArn}(TagResource)DELETE /tags/{resourceArn}?tagKeys=...(UntagResource)GET /tags/{resourceArn}(ListTagsForResource)
The tagging operations work on application and job run ARNs, as CreateApplication and StartJobRun
return them (arn:aws:emr-serverless:<region>:<account>:/applications/<id> and
.../applications/<id>/jobruns/<id>). They share the tags those calls store, so GetApplication and
GetJobRun always report the current set. Following the EMR Serverless user guide, a resource holds
at most 50 tags, and aws: in any case is reserved as the prefix of a tag key or value. A session ARN
(.../sessions/<id>) answers ResourceNotFoundException, as sessions are not emulated. Once an
application is deleted, its ARN and its runs' ARNs answer ResourceNotFoundException too, while
GetApplication and GetJobRun still report them.
Applications, job runs, creation client tokens, and tags are scoped to the request's AWS Region. An application or run created in one Region is not returned by list, get, or tag requests signed for another.
ListApplications refuses a states filter naming a state that does not exist, or more than 7, and a
maxResults outside 1 to 50, with the ValidationException AWS's validation layer answers.
CreateApplication stores every configuration UpdateApplication does, runtimeConfiguration,
monitoringConfiguration, schedulerConfiguration, diskEncryptionConfiguration,
interactiveConfiguration, identityCenterConfiguration and jobLevelCostAllocationConfiguration
among them, and GetApplication returns each as it was written.
DeleteApplication leaves the application in TERMINATED state. GetApplication continues to
report that state so lifecycle waiters can observe it, while an unfiltered ListApplications
omits the terminated application. A terminated application cannot be started or stopped again.
Job runs
In the default immediate runner mode, job runs are metadata only: nothing executes. A run follows
the job run states and GetJobRun's response shape, and settles when it is read. In the docker
runner mode a Spark run executes; see Running Spark job runs.
- Lifecycle: a run is
RUNNINGfrom the moment it is submitted. With the defaultjob-run-duration-secondsof0, aBATCHrun isSUCCESSas soon as it starts; a positive duration keeps itRUNNINGthat long. A run whose duration would pass itsexecutionTimeoutMinutes(720 when not given, as AWS reports it) isCANCELLEDat the timeout. ASTREAMINGrun staysRUNNINGuntil it is cancelled. - Auto-start: a run submitted to a
CREATEDorSTOPPEDapplication starts the application, asautoStartConfiguration.enableddefaults totrue. With auto-start turned off, the run is refused withValidationExceptionuntil the application is started. A run on a terminated application is refused. - Idempotency:
clientTokenis the idempotency token. Repeating a request with the same token returns the original run; reusing the token with a different request answersConflictException(HTTP 409) "Request did not match the original". - Execution timeout:
executionTimeoutMinutesis 0 to 1,000,000, 0 meaning no timeout. From releaseemr-7.11.0, aBATCHrun's timeout must be 1 to 10080 minutes (7 days), as the model and the 7.11.0 release notes say; a run outside that is refused withValidationException. - CancelJobRun moves a run that has not finished to
CANCELLED. A finished run answersValidationException"Job run is not in a cancellable state". - ListJobRuns returns the newest runs first, filtered by
states,createdAtAfter,createdAtBeforeandmode, at most 50 per page. With severalstates, the runs are grouped by state in the order the filter names them. A state or mode that does not exist, or more than 8 states, is refused withValidationException. An unknown application has no runs. AnextTokenresumes only the listing it came from, with the same application and filters. - Attempts: a run starts as attempt 1, and in the
immediatemode, where none fails, it stays its only one. In thedockermode a run whose driver fails is tried again on release 7.1.0 or later, as the user guide's "Job resiliency" gives it: aBATCHrun until it has maderetryPolicy.maxAttemptsattempts (1 by default, no retry), and aSTREAMINGrun until it has failedmaxFailedAttemptsPerHourtimes within an hour (5 by default). Either outside 1 to 10, the user guide's "Accepted values", is refused withValidationException, and either not an integer withSerializationException. Each new attempt isSCHEDULEDagain and runs its driver from the beginning; a cancelled run, one past its timeout, and one Floci's own shutdown stopped are not tried again.GetJobRunwithoutattemptreturns the latest attempt, withattemptan earlier one as it ended (FAILED, with itsstateDetails), and an attempt the run never made answersResourceNotFoundException; one below 1 or not an integer isValidationException.ListJobRunAttemptslists every attempt, oldest first, each with its own creation and update times. No source says whether a run's timeout spans its attempts; Floci applies it to each. createdByis the caller's ARN, asGetCallerIdentityreports it.releaseLabelandnetworkConfigurationcome from the application.
A state machine drives applications and job runs through the emr-serverless: integrations, .sync
included; see Step Functions: Amazon EMR Serverless tasks.
Running Spark job runs
With runner-mode set to docker (FLOCI_SERVICES_EMRSERVERLESS_RUNNER_MODE=docker), a Spark job
run executes. Floci starts one container per run from the application's custom image, if it names one
(see Image below), or else from the release's image, the base image AWS publishes for customizing
EMR Serverless images (public.ecr.aws/emr-serverless/spark/<release>, and spark4/<release> for the
AWS runtime for Apache Spark releases, emr-spark-8.0.0 on), and runs
spark-submit in local mode in it: the container holds the driver and its executors.
-
States: a run is
SCHEDULEDwhile its image is pulled and its container starts (the first run of a release pulls its image, 3.5 to 4.3 GB unpacked; a pull still downloading afterfloci.docker.image-pull-timeout-seconds, five minutes by default, is tried again, three attempts in all, so on a slow connection raise it or rundocker pullon the image first, or the run isFAILEDwith "Could not pull image"), andRUNNINGonce the Spark driver runs, which setsstartedAt. It isSUCCESSwhen the driver exits with code 0 andFAILEDotherwise, with the exit code instateDetails.CancelJobRun, or aBATCHrun passing itsexecutionTimeoutMinutes, makes itCANCELLINGuntil the driver is stopped, thenCANCELLED, as the job run states describe. A run Floci was running when it stopped isFAILEDonce it is read again. Floci's shutdown and a state reset stop every driver, one whose image is still being pulled included, and a driver a hard stop left running is removed the first time job runs are used after Floci restarts, unlessreconcile-containers-on-startupis off. -
What
spark-submitgets: theentryPoint, itsentryPointArgumentsand thesparkSubmitParameters, after thespark-defaultsproperties of the application'sruntimeConfiguration, or the run's own inconfigurationOverrides.applicationConfiguration, which replace the application's wholespark-defaultsclassification. Fromemr-spark-8.1.0the two are merged by property instead, the run's winning.s3://ands3a://paths reach Floci's S3 through S3A, on releases before 7.10.0 too, wheres3://would otherwise be EMRFS; the entry point and its files can be read from there. The Glue Data Catalog client is pointed at Floci's Glue. -
Driver environment and archives: a
spark.emr-serverless.driverEnv.<KEY>property, from thespark-defaultsabove or a--confinsparkSubmitParameters, which wins, is an environment variable of the container, replacing one of Floci's own of that name, such as the user guide'sJAVA_HOMEfor Java 17. Each archive ofspark.archives(whichspark-submit's--archivessets, winning over a--conf) that is in Floci's S3 is unpacked into the container's working directory,/home/hadoopin the release's image, before the driver starts, under the name that follows its#, or else its file's name: a.jaror.zipis unzipped, a.tar.gz,.tgzor.taruntarred, and any other file copied, as Spark unpacks one. So the user guide's Python virtual environment runs as it is written there:--conf spark.archives=s3://amzn-s3-demo-bucket/EXAMPLE-PREFIX/pyspark_venv.tar.gz#environment --conf spark.emr-serverless.driverEnv.PYSPARK_DRIVER_PYTHON=./environment/bin/python --conf spark.emr-serverless.driverEnv.PYSPARK_PYTHON=./environment/bin/python --conf spark.executorEnv.PYSPARK_PYTHON=./environment/bin/pythonFloci reads each archive as the run's account. One it cannot read fails the run before its driver starts, with "Job run could not start" naming it, and one that does not unpack fails the run as a driver's failure does. Spark also unpacks every archive itself, into its own files folder, where
SparkFiles.getfinds it. Aspark.executorEnv.<KEY>needs nothing more from Floci: local mode's executors run in the driver's JVM, and Spark gives these variables to the Python workers it starts. -
Credentials: the container gets a session for the run's execution role when IAM knows the role, otherwise the account's placeholder credentials, and
AWS_ENDPOINT_URLpointing at Floci, so the job's own SDK clients reach Floci too. -
HTTPS: with TLS on, the container also gets Floci's CA bundle as a Java trust store,
/etc/floci-ca-bundle.p12, which every JVM in it uses throughJAVA_TOOL_OPTIONS, each saying so on its standard error (Picked up JAVA_TOOL_OPTIONS: ...); a trust store the job names itself, with-Djavax.net.ssl.trustStore, replaces it. So the job trusts Floci over HTTPS, and withFLOCI_DNS_SPOOF_AWS_ENDPOINTSon as well, which leads AWS's own endpoint names to Floci, SDK clients that ignoreAWS_ENDPOINT_URL, the AWS SDK for Java 1.x's for one, reach Floci unchanged. -
Output: the driver's output goes to Floci's log, prefixed
emr-serverless:<jobRunId>. With an S3 log destination, the run'ss3MonitoringConfigurationor else the application's, its standard output and error also go to Floci's S3 once the run ends, gzipped, asstdout.gzandstderr.gzunder<logUri>/applications/<applicationId>/jobs/<jobRunId>/SPARK_DRIVER/, withattempts/<n>/beforeSPARK_DRIVER/for aSTREAMINGrun, or aBATCHrun whoseretryPolicyallows more than one attempt, on release 7.1.0 or later, each attempt's logs under its own number. A cancelled run's logs hold what its driver wrote until it was stopped. Logs that cannot be written, to a bucket that does not exist say, leave the run as it ended. -
CloudWatch Logs: with CloudWatch logging enabled, the run's
cloudWatchLoggingConfigurationor else the application's ("enabled": falseat the run turns it off), the driver's standard output and error go line by line, while it runs, to the log streams<prefix>/applications/<applicationId>/jobs/<jobRunId>/SPARK_DRIVER/stdoutand.../stderrin Floci's CloudWatch Logs, withattempts/<n>/beforeSPARK_DRIVERas for S3. The log group islogGroupName,/aws/emr-serverlessby default, and<prefix>thelogStreamNamePrefix, if any; both are created as needed, in the run's account and Region. AlogTypessends only the driver's types it names, and none of the driver's output when it names onlySPARK_EXECUTOR. -
Image: an application's custom image runs in place of the release's: the
Driverworker type'simageConfigurationinworkerTypeSpecifications, or else the application'simageConfiguration, which applies to every worker type (local mode runs the executors in the driver's container, so anExecutorimage is not used). An<account>.dkr.ecr.<region>.amazonaws.com/<repository>:<tag>URI leads to Floci's ECR, as a Lambda function's or an ECS task's image does, so the image is pushed to a repository there; therepositoryUriFloci's ECR hands out works too. The image is pulled again for every run, so a tag pushed again is what the next run gets; when the pull fails the image the Docker daemon already has runs, one built locally under that URI included, and without one the run isFAILEDwith "Job run could not start".CreateApplicationrefuses an image configuration without animageUri, andCreateApplicationandUpdateApplicationan image whose ECR repository, AWS-shaped or arepositoryUrifrom Floci's ECR, is in another Region, both withValidationExceptionin Floci's own wording. An update that leavesimageUriout removes that image configuration. Without a custom image,image-templatenames another image than the release's, such as a mirror or a dated tag of it:registry.internal/emr-serverless/spark/%s:20250425.
Limitations and Differences from AWS
- Jobs do not execute by default: in the
immediaterunner modeStartJobRunrecords a job run and moves it through its states, but nothing runs. In thedockermode a Spark run executes in local mode in one container, so worker counts and sizes, initial and maximum capacity are not applied; a Hive run isFAILEDwithout running, in Floci's own wording, as is a driver's failure. Of the monitoring configuration, the S3 log destination gets the driver'sstdout.gzandstderr.gzonce a run ends (no event logs, rotated files or uploads while it runs), and CloudWatch Logs the driver's output while it runs (there are no executor logs, local mode having no executors, andencryptionKeyArnis ignored). - Unsourced errors: AWS documents neither the error for a run submitted to an application whose auto-start is off nor the one for a run on a terminated application; Floci answers both with
ValidationException. The same holds for aBATCHtimeout outside 1 to 10080 minutes onemr-7.11.0or later (ValidationException) and forGetJobRunnaming an attempt a run never made (ResourceNotFoundException), both in Floci's own wording. A run needs ajobDriver, as everyJobRuncarries one, andjobDriveris a union, so a run without a driver, or with one that sets bothsparkSubmitandhiveor neither, is refused withValidationExceptiontoo, in Floci's own wording. - Archives: only the archives of
spark.archivesthat are in S3 are unpacked into the driver's working directory; Spark alone unpacks the others, into its own files folder. Floci reads an archive itself, whatever the execution role may read, though Spark's own read of it uses the role's credentials. - Custom images: Floci does not check an
imageUriagainst the model's pattern, which would refuse the repository URIs Floci's own ECR hands out, nor that the image was built from its release's base image (AWS refuses one that was not fromemr-7.14.0andemr-spark-8.1.0on), nor the image's size. An image that cannot be pulled fails the run, not the request that names it. Every run resolves its image again, as releases from 7.14 do and earlier ones withapplicationLevelDigestResolutionfalse: Floci keeps no digest from the application's start, and reports noresolvedImageDigest, on the application or on a job run. - StopApplication with running jobs: AWS requires running jobs to finish or be cancelled before an application stops. Floci does not enforce it; with the default duration of
0noBATCHrun is ever running. - Not emulated: the "EMR Serverless Job Run Retry" event, as Floci sends no EMR Serverless events, queuing (
QUEUED),totalResourceUtilizationandbilledResourceUtilization, andshutdownGracePeriodInSeconds(accepted and ignored: a cancelled run's driver is stopped at once). - Instant Start/Stop: Floci marks the application
STARTEDorSTOPPEDimmediately without provisioning actual compute capacity in the background. - Data Plane: Floci does not implement the data-plane API, such as interactive sessions.