匯出可供 Operator 使用的動態環境變數¶
在 airflow_local_settings.py 中定義的 get_airflow_context_vars 返回的鍵值對會被注入到預設的 Airflow 上下文環境變數中,這些變數在執行任務時可作為環境變數使用。請注意,鍵和值都必須是字串。
dag_id、task_id、execution_date、dag_run_id、dag_owner、dag_email 是保留鍵。
例如,在您的 airflow_local_settings.py 檔案中
def get_airflow_context_vars(context) -> dict[str, str]:
"""
:param context: The context for the task_instance of interest.
"""
# more env vars
return {"airflow_cluster": "main"}
有關如何配置本地設定的詳細資訊,請參閱配置本地設定。