how do I use the --conf option in airflow

Praveen Singh picture Praveen Singh · Aug 29, 2017 · Viewed 14.8k times · Source

I am trying to run a airflow DAG and need to pass some parameters for the tasks.

How do I read the JSON string passed as the --conf parameter in the command line trigger_dag command, in the python DAG file.

ex: airflow trigger_dag 'dag_name' -r 'run_id' --conf '{"key":"value"}'

Answer

Daniel Huang picture Daniel Huang · Aug 31, 2017

Two ways. From inside a template field or file:

{{ dag_run.conf['key'] }}

Or when context is available, e.g. within a python callable of the PythonOperator:

context['dag_run'].conf['key']