This repo contains an Astronomer project with multiple examples showing how to dynamically generate DAGs in Airflow. A guide discussing these concepts in depth will be published shortly.
This repo contains DAGs and supporting Python scripts that dynamically generate DAGs using multiple methods. They are described here, organized by folder.
dynamic-dags-connections.py
generates DAGs based on Airflow connections.dynamic-dags-loop.py
generates DAGs based on a simple range() loop.dynamic-dags-variable.py
generates DAGs based on an Airflow variables.dag_file_1.py
anddag_file_2.py
are actual DAG files that were dynamically generated using scripts in theinclude/
directory, described below.
dag-config/
contains two Json configuration files with parameters used to dynamically generate Python files fordag_file_1.py
anddag_file_2.py
.dag-template.py
contains the starting DAG template from which other DAG files are dynamically generated.generate-dag-files.py
contains a script to dynamically generate a DAG file for each config file indag-config/
by making a copy ofdag-template.py
and replacing key parameters from the config file.
The easiest way to run these example DAGs is to use the Astronomer CLI to get an Airflow instance up and running locally:
- Install the Astronomer CLI
- Clone this repo somewhere locally and navigate to it in your terminal
- Initialize an Astronomer project by running
astro dev init
- Start Airflow locally by running
astro dev start
- Navigate to localhost:8080 in your browser and you should see the tutorial DAGs there