[Python] How to get parameters in Airflow

Jua KIM·2021년 12월 14일
0

python

목록 보기
2/2
from airflow import DAG
from airflow.utils.dates import days_ago
from airflow.operators.bash import BashOperator
from airflow.operators.python import PythonOperator

# for python operator
def test(ds, **kwargs):
	print(f"{kwargs['dag_run'].conf['message']}")

with DAG(
	dag_id='test',
    	start_date=days_ago(2),
    	schedule_interval=None) as dag:
	py_test = PythonOperator(
          task_id='test_python',
          provide_context=True,
          python_callable=test,
          dag=dag)

	bash_test = BashOperator(
          task_id='test_bash',
          bash_command='echo "here is message: "'
		       '{dag_run.conf["message" if dag_run else ""]}',
          dag=dag)

py_test >> bash_test

using the airflow UI, you can use "Actions".

Write the args in json format.

reference: https://stackoverflow.com/questions/53663534/for-apache-airflow-how-can-i-pass-the-parameters-when-manually-trigger-dag-via

profile
AI/ML engineer

0개의 댓글