Amazon Managed Workflows for Apache Airflow (MWAA)¶
Amazon Managed Workflows for Apache Airflow (MWAA) is a managed service for Apache Airflow that lets you use your current, familiar Apache Airflow platform to orchestrate your workflows. You gain improved scalability, availability, and security without the operational burden of managing underlying infrastructure.
Note: Unlike Airflow’s built-in operators, these operators are meant for interaction with external Airflow environments hosted on AWS MWAA.
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¶
Trigger a DAG run in an Amazon MWAA environment¶
To trigger a DAG run in an Amazon MWAA environment you can use the
MwaaTriggerDagRunOperator
In the following example, the task trigger_dag_run
triggers a DAG run for the DAG hello_world
in the environment
MyAirflowEnvironment
.
amazon/tests/system/amazon/aws/example_mwaa.py
trigger_dag_run = MwaaTriggerDagRunOperator(
task_id="trigger_dag_run",
env_name=env_name,
trigger_dag_id=trigger_dag_id,
)
Sensors¶
Wait on the state of an AWS MWAA DAG Run¶
To wait for a DAG Run running on Amazon MWAA until it reaches one of the given states, you can use the
MwaaDagRunSensor
In the following example, the task wait_for_dag_run
waits for the DAG run created in the above task to complete.
amazon/tests/system/amazon/aws/example_mwaa.py
wait_for_dag_run = MwaaDagRunSensor(
task_id="wait_for_dag_run",
external_env_name=env_name,
external_dag_id=trigger_dag_id,
external_dag_run_id="{{ task_instance.xcom_pull(task_ids='trigger_dag_run')['RestApiResponse']['dag_run_id'] }}",
poke_interval=5,
)