Introducing Amazon MWAA help for Apache Airflow model 2.7.2 and deferrable operators







Amazon Managed Workflow for Apache Airflow (Amazon MWAA) is a managed service that permits you to use a well-known Apache Airflow setting with improved scalability, availability, and safety to boost and scale what you are promoting workflows with out the operational burden of managing the underlying infrastructure.

Immediately, we’re asserting the provision of Apache Airflow model 2.7.2 environments and help for deferrable operators on Amazon MWAA. On this publish, we offer an outline of deferrable operators and triggers, together with a walkthrough of an instance showcasing the best way to use them. We additionally delve into a number of the new options and capabilities of Apache Airflow, and how one can arrange or improve your Amazon MWAA setting to model 2.7.2.

Deferrable operators and triggers

Customary operators and sensors repeatedly occupy an Airflow employee slot, no matter whether or not they’re lively or idle. For instance, even whereas ready for an exterior system to finish a job, a employee slot is consumed. The Gantt chart under, representing a Directed Acyclic Graph (DAG), showcases this situation by means of a number of Amazon Redshift operations.

Gantt chart representing DAG idle time

You possibly can see the time every activity spends idling whereas ready for the Redshift cluster to be created, snapshotted, and paused. With the introduction of deferrable operators in Apache Airflow 2.2, the polling course of will be offloaded to make sure environment friendly utilization of the employee slot. A deferrable operator can droop itself and resume as soon as the exterior job is full, as an alternative of repeatedly occupying a employee slot. This minimizes queued duties and results in a extra environment friendly utilization of assets inside your Amazon MWAA setting. The next determine reveals a simplified diagram describing the method movement.

After a activity has deferred its run, it frees up the employee slot and assigns the examine of completion to a small piece of asynchronous code known as a set off. The set off runs in a father or mother course of known as a triggerer, a service that runs an asyncio occasion loop. The triggerer has the potential to run triggers in parallel at scale, and to sign duties to renew when a situation is met.

The Amazon supplier package deal for Apache Airflow has added triggers for standard AWS providers like AWS Glue and Amazon EMR. In Amazon MWAA environments working Apache Airflow v2.7.2, the administration and operation of the triggerer service is taken care of for you. Should you desire to not use the triggerer service, you may change the configuration mwaa.triggerer_enabled. Moreover, you may outline what number of triggers every triggerer can run in parallel utilizing the configuration parameter triggerer.default_capacity. This parameter defaults to values primarily based in your Amazon MWAA setting class. Confer with the Configuration reference within the Consumer Information for detailed configuration values.

When to make use of deferrable operators

Deferrable operators are notably helpful for duties that submit jobs to methods exterior to an Amazon MWAA setting, equivalent to Amazon EMR, AWS Glue, and Amazon SageMaker, or different sensors ready for a selected occasion to happen. These duties can take minutes to hours to finish and are primarily idle operators, making them good candidates to get replaced by their deferrable variations. Some extra use instances embody:

  • File system-based operations.
  • Database operations with lengthy working queries.

Utilizing deferrable operators in Amazon MWAA

To make use of deferrable operators in Amazon MWAA, make sure you’re working Apache Airflow model 2.7 or higher in your Amazon MWAA setting, and the operators or sensors in your DAGs help deferring. Operators within the Amazon supplier package deal expose a deferrable parameter which you’ll be able to set to True to run the operator in asynchronous mode. For instance, you should use S3KeySensor in asynchronous mode as follows:

wait_for_source_data = S3KeySensor (
bucket_key = "object_key",

You may also make the most of varied pre-built deferrable operators accessible in different supplier packages, equivalent to Snowflake and Databricks.

Observe the entire pattern code within the GitHub repository to grasp how deferrable operators work collectively. You’ll be constructing and orchestrating the information pipeline illustrated within the following determine.

The pipeline consists of three levels:

  • A S3KeySensor that waits for a dataset to be uploaded in Amazon Easy Storage Service (Amazon S3)
  • An AWS Glue crawler to categorise objects within the dataset and save schemas into the AWS Glue Information Catalog
  • An AWS Glue job that makes use of the metadata within the Information Catalog to denormalize the supply dataset, create Information Catalog tables primarily based on filtered knowledge, and write the ensuing knowledge again to Amazon S3 in separate Apache Parquet recordsdata.

Setup and Teardown duties

It’s frequent to construct workflows that require ephemeral assets, for instance an S3 bucket to quickly retailer knowledge, databases and corresponding datasets to run high quality checks, or a compute cluster to coach a mannequin in a machine studying (ML) orchestration pipeline. It’s worthwhile to have these assets correctly configured earlier than working work duties, and after their run, guarantee they’re torn down. Doing this manually is advanced. It might result in poor readability and maintainability of your DAGs, and depart assets working continuously, thereby rising prices. With Amazon MWAA help for Apache Airflow model 2.7.2, you should use two new varieties of duties to help this situation: setup and teardown duties.

Setup and teardown duties be sure that the assets wanted for a piece activity are arrange earlier than the duty begins its run after which are taken down after it has completed, even when the work activity fails. Any activity will be configured as a setup or teardown activity. As soon as configured, they’ve particular visibility within the Airflow UI and likewise particular conduct. The next graph describes a easy knowledge high quality examine pipeline utilizing setup and teardown duties.

One choice to mark setup_db_instance and teardown_db_instance as setup and teardown duties is to make use of the as_teardown() technique within the teardown activity within the dependencies chain declaration. Notice that the tactic receives the setup activity as a parameter:

setup_db_instance >> column_quality_check >> row_count_quality_check >> teardown_db_instance.as_teardown(setups=setup_db_instance)

Another choice is to make use of @setup and @teardown decorators:

from airflow.decorators import setup

def setup_db_instance():
return "Assets absolutely setup"


After you configure the duties, the graph view reveals your setup duties with an upward arrow and your teardown duties with a downward arrow. They’re linked by a dotted line depicting the setup/teardown workflow. Any activity between the setup and teardown duties (equivalent to column_quality_check and row_count_quality_check) are within the scope of the workflow. This association entails the next conduct:

  • Should you clear column_quality_check or row_count_quality_check, each setup_db_instance and teardown_db_instance might be cleared
  • If setup_db_instance runs efficiently, and column_quality_check and row_count_quality_check have accomplished, no matter whether or not they had been profitable or not, teardown_db_instance will run
  • If setup_db_instance fails or is skipped, then teardown_db_instance will fail or skip
  • If teardown_db_instance fails, by default Airflow ignores its standing to judge whether or not the pipeline run was profitable

Notice that when creating setup and teardown workflows, there will be a couple of set of setup and teardown duties, and they are often parallel and nested. Neither setup nor teardown duties are restricted in quantity, nor are the employee duties you may embody within the scope of the workflow.

Observe the entire pattern code within the GitHub repository to grasp how setup and teardown duties work.

When to make use of setup and teardown duties

Setup and teardown duties are helpful to enhance the reliability and cost-effectiveness of DAGs, guaranteeing that required assets are created and deleted in the fitting time. They will additionally assist simplify advanced DAGs by breaking them down into smaller, extra manageable duties, bettering maintainability. Some use instances embody:

  • Information processing primarily based on ephemeral compute, like Amazon Elastic Compute Cloud (Amazon EC2) situations fleets or EMR clusters
  • ML mannequin coaching or tuning pipelines
  • Extract, remodel, and cargo (ETL) jobs utilizing exterior ephemeral knowledge shops to share knowledge amongst Airflow duties

With Amazon MWAA help for Apache Airflow model 2.7.2, you can begin utilizing setup and teardown duties to enhance your pipelines as of as we speak. To be taught extra about Setup and Teardown duties, consult with the Apache Airflow documentation.

Secrets and techniques cache

To mirror modifications to your DAGs and duties, the Apache Airflow scheduler parses your DAG recordsdata repeatedly, each 30 seconds by default. In case you have variables or connections as top-level code (code outdoors the operator’s execute strategies), a request is generated each time the DAG file is parsed, impacting parsing velocity and resulting in sub-optimal efficiency within the DAG file processing. If you’re working at scale, it has the potential to have an effect on Airflow efficiency and scalability as the quantity of community communication and cargo on the metastore database improve. Should you’re utilizing an alternate secrets and techniques backend, equivalent to AWS Secrets and techniques Supervisor, each DAG parse is a brand new request to that service, rising prices.

With Amazon MWAA help for Apache Airflow model 2.7.2, you should use secrets and techniques cache for variables and connections. Airflow will cache variables and connections regionally in order that they are often accessed quicker throughout DAG parsing, with out having to fetch them from the secrets and techniques backend, environments variables, or metadata database. The next diagram describes the method.

Enabling caching will assist decrease the DAG parsing time, particularly if variables and connections are utilized in top-level code (which isn’t a finest follow). With the introduction of a secrets and techniques cache, the frequency of API calls to the backend is decreased, which in flip lowers the general price related to backend entry. Nevertheless, much like different caching implementations, a secrets and techniques cache could serve outdated values till the time to dwell (TTL) expires.

When to make use of the secrets and techniques cache function

You must think about using the secrets and techniques cache function to enhance efficiency and reliability, and to scale back the working prices of your Airflow duties. That is notably helpful in case your DAG regularly retrieves variables or connections within the top-level Python code.

The way to use the secrets and techniques cache function on Amazon MWAA

To allow the secrets and techniques cache, you may set the secrets and techniques.use_cache setting configuration parameter to True. As soon as enabled, Airflow will robotically cache secrets and techniques when they’re accessed. The cache will solely be used throughout DAG recordsdata parsing, and never throughout DAG runtime.

You may also management the TTL of saved values for which the cache is taken into account legitimate utilizing the setting configuration parameter secrets and techniques.cache_ttl_seconds, which is defaulted to fifteen minutes.

Operating or failed filters and Cluster Exercise web page

Figuring out DAGs in failed state will be difficult for big Airflow situations. You usually end up scrolling by means of pages looking for failures to deal with. With Apache Airflow model 2.7.2 environments in Amazon MWAA, now you can filter DAGs at present working and DAGs with failed DAG runs. As you may see within the following screenshot, two standing tabs, Operating and Failed, had been added to the UI.

One other benefit of Amazon MWAA environments utilizing Apache Airflow model 2.7.2 is the brand new Cluster Exercise web page for environment-level monitoring.

The Cluster Exercise web page gathers helpful knowledge to watch your cluster’s dwell and historic metrics. Within the high part of the web page, you get dwell metrics on the variety of DAGs able to be scheduled, the highest 5 longest working DAGs, slots utilized in totally different swimming pools, and elements well being (meta database, scheduler, and triggerer). The next screenshot reveals an instance of this web page.

The underside part of the Cluster Exercise web page contains historic metrics of DAG runs and activity situations states.

Arrange a brand new Apache Airflow v2.7.2 setting in Amazon MWAA

Establishing a brand new Apache Airflow model 2.7.2 setting in Amazon MWAA not solely supplies new options, but in addition leverages Python 3.11 and the Amazon Linux 2023 (AL2023) base picture, providing enhanced safety, fashionable tooling, and help for the most recent Python libraries and options. You possibly can provoke the arrange in your account and most well-liked Area utilizing the AWS Administration Console, API, or AWS Command Line Interface (AWS CLI). Should you’re adopting infrastructure as code (IaC), you may automate the setup utilizing AWS CloudFormation, the AWS Cloud Growth Package (AWS CDK), or Terraform scripts.

Upon profitable creation of an Apache Airflow model 2.7.2 setting in Amazon MWAA, sure packages are robotically put in on the scheduler and employee nodes. For an entire checklist of put in packages and their variations, consult with this MWAA documentation. You possibly can set up extra packages utilizing a necessities file. Starting with Apache Airflow model 2.7.2, your necessities file should embody a --constraints assertion. If you don’t present a constraint, Amazon MWAA will specify one so that you can make sure the packages listed in your necessities are appropriate with the model of Apache Airflow you’re utilizing.

Improve from older variations of Apache Airflow to Apache Airflow v2.7.2

Make the most of these newest capabilities by upgrading your older Apache Airflow v2.x-based environments to model 2.7.2 utilizing in-place model upgrades. To be taught extra about in-place model upgrades, consult with Upgrading the Apache Airflow model or Introducing in-place model upgrades with Amazon MWAA.


On this publish, we mentioned deferrable operators together with some important modifications launched in Apache Airflow model 2.7.2, such because the Cluster Exercise web page within the UI, the cache for variables and connections, and how one can get began utilizing them in Amazon MWAA.

For added particulars and code examples on Amazon MWAA, go to the Amazon MWAA Consumer Information and the Amazon MWAA examples GitHub repo.

Apache, Apache Airflow, and Airflow are both registered emblems or emblems of the Apache Software program Basis in the US and/or different nations.

In regards to the Authors

Manasi Bhutada is an ISV Options Architect primarily based within the Netherlands. She helps prospects design and implement properly architected options in AWS that handle their enterprise issues. She is obsessed with knowledge analytics and networking. Past work she enjoys experimenting with meals, enjoying pickleball, and diving into enjoyable board video games.

Hernan Garcia is a Senior Options Architect at AWS primarily based within the Netherlands. He works within the Monetary Providers Business supporting enterprises of their cloud adoption. He’s obsessed with serverless applied sciences, safety, and compliance. He enjoys spending time with household and mates, and attempting out new dishes from totally different cuisines.


Supply hyperlink

Share this


Google Presents 3 Suggestions For Checking Technical web optimization Points

Google printed a video providing three ideas for utilizing search console to establish technical points that may be inflicting indexing or rating issues. Three...

A easy snapshot reveals how computational pictures can shock and alarm us

Whereas Tessa Coates was making an attempt on wedding ceremony clothes final month, she posted a seemingly easy snapshot of herself on Instagram...

Recent articles

More like this


Please enter your comment!
Please enter your name here