Amazon EMR Serverless Operators¶
Amazon EMR Serverless is a serverless option in Amazon EMR that makes it easy for data analysts and engineers to run open-source big data analytics frameworks without configuring, managing, and scaling clusters or servers. You get all the features and benefits of Amazon EMR without the need for experts to plan and manage clusters.
Prerequisite Tasks¶
To use these operators, you must do a few things:
Create necessary resources using AWS Console or AWS CLI.
Install API libraries via pip.
pip install 'apache-airflow[amazon]'Detailed information is available Installation of Airflow®
Generic Parameters¶
- aws_conn_id
Reference to Amazon Web Services Connection ID. If this parameter is set to
None
then the default boto3 behaviour is used without a connection lookup. Otherwise use the credentials stored in the Connection. Default:aws_default
- region_name
AWS Region Name. If this parameter is set to
None
or omitted then region_name from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None
- verify
Whether or not to verify SSL certificates.
False
- Do not validate SSL certificates.path/to/cert/bundle.pem - A filename of the CA cert bundle to use. You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.
If this parameter is set to
None
or is omitted then verify from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None
- botocore_config
The provided dictionary is used to construct a botocore.config.Config. This configuration can be used to configure Avoid Throttling exceptions, timeouts, etc.
Example, for more detail about parameters please have a look botocore.config.Config¶{ "signature_version": "unsigned", "s3": { "us_east_1_regional_endpoint": True, }, "retries": { "mode": "standard", "max_attempts": 10, }, "connect_timeout": 300, "read_timeout": 300, "tcp_keepalive": True, }
If this parameter is set to
None
or omitted then config_kwargs from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default:None
Note
Specifying an empty dictionary,
{}
, will overwrite the connection configuration for botocore.config.Config
Operators¶
Create an EMR Serverless Application¶
You can use EmrServerlessCreateApplicationOperator
to
create a new EMR Serverless Application.
This operator can be run in deferrable mode by passing deferrable=True
as a parameter. This requires
the aiobotocore module to be installed.
emr_serverless_app = EmrServerlessCreateApplicationOperator(
task_id="create_emr_serverless_task",
release_label="emr-6.6.0",
job_type="SPARK",
config={"name": "new_application"},
)
Start an EMR Serverless Job¶
You can use EmrServerlessStartJobOperator
to
start an EMR Serverless Job.
This operator can be run in deferrable mode by passing deferrable=True
as a parameter. This requires
the aiobotocore module to be installed.
start_job = EmrServerlessStartJobOperator(
task_id="start_emr_serverless_job",
application_id=emr_serverless_app_id,
execution_role_arn=role_arn,
job_driver=SPARK_JOB_DRIVER,
configuration_overrides=SPARK_CONFIGURATION_OVERRIDES,
)
Open Application UIs¶
The operator can also be configured to generate one-time links to the application UIs and Spark stdout logs
by passing the enable_application_ui_links=True
as a parameter. Once the job starts running, these links
are available in the Details section of the relevant Task. If enable_application_ui_links=False
then the
links will be present but grayed out.
You need to ensure you have the following IAM permissions to generate the dashboard link.
"emr-serverless:GetDashboardForJobRun"
If Amazon S3 or Amazon CloudWatch logs are enabled for EMR Serverless, links to the respective console will also be available in the task logs and task Details.
Stop an EMR Serverless Application¶
You can use EmrServerlessStopApplicationOperator
to
stop an EMR Serverless Application.
This operator can be run in deferrable mode by passing deferrable=True
as a parameter. This requires
the aiobotocore module to be installed.
stop_app = EmrServerlessStopApplicationOperator(
task_id="stop_application",
application_id=emr_serverless_app_id,
force_stop=True,
)
Delete an EMR Serverless Application¶
You can use EmrServerlessDeleteApplicationOperator
to
delete an EMR Serverless Application.
This operator can be run in deferrable mode by passing deferrable=True
as a parameter. This requires
the aiobotocore module to be installed.
delete_app = EmrServerlessDeleteApplicationOperator(
task_id="delete_application",
application_id=emr_serverless_app_id,
)
Sensors¶
Wait on an EMR Serverless Job state¶
To monitor the state of an EMR Serverless Job you can use
EmrServerlessJobSensor
.
wait_for_job = EmrServerlessJobSensor(
task_id="wait_for_job",
application_id=emr_serverless_app_id,
job_run_id=start_job.output,
# the default is to wait for job completion, here we just wait for the job to be running.
target_states={*EmrServerlessHook.JOB_SUCCESS_STATES, "RUNNING"},
)
Wait on an EMR Serverless Application state¶
To monitor the state of an EMR Serverless Application you can use
EmrServerlessApplicationSensor
.
wait_for_app_creation = EmrServerlessApplicationSensor(
task_id="wait_for_app_creation",
application_id=emr_serverless_app_id,
)