A union of curiosity and data science

Knowledgebase and brain dump of a database engineer

Airflow - access Configuration JSON (Optional) in DAG

Access parameters passed to airflow dag from airflow UI.


use kwargs instead of {{ dag_run.conf }} to access trigger params.


1. To use this data you must setup configs. 

a. add config - airflow.cfg : dag_run_conf_overrides_params=True
b. if Amazon MWAA Configs : core.dag_run_conf_overrides_params=True


2. Get the data from kwargs in your function. 

from datetime import datetime
from airflow import DAG
from airflow.operators.python_operator import PythonOperator

def print_configs(ds, **kwargs):
    print("dag_run: ", kwargs['params']) 
    print("ds:", ds)  

dag = DAG('manual_config_run_test', description='manual configs', schedule_interval='0 12 * * *', start_date=datetime(2021, 7, 11), catchup=False)

print_d = PythonOperator(task_id='print_manually_passed_configs', python_callable=print_configs, dag=dag, provide_context=True)



Note the "provide_context=True" in the python operator call. 


Result in the log : 

[2021-07-12 18:27:50,651] {{logging_mixin.py:112}} INFO - dag_run: {'end_date': '2021-07-12'}
[2021-07-12 18:27:50,707] {{logging_mixin.py:112}} INFO - ds: 2021-07-12
[2021-07-12 18:27:50,762] {{python_operator.py:114}} INFO - Done. Returned value was: None