Export dynamic environment variables available for operators to use¶
The key value pairs returned in get_airflow_context_vars defined in
airflow_local_settings.py are injected to default airflow context environment variables,
which are available as environment variables when running tasks. Note, both key and
value are must be string.
dag_id, task_id, execution_date, dag_run_id,
dag_owner, dag_email are reserved keys.
- Create - airflow_local_settings.pyfile and put in on- $PYTHONPATHor to- $AIRFLOW_HOME/configfolder. (Airflow adds- $AIRFLOW_HOME/configon- PYTHONPATHwhen Airflow is initialized)
- Define - get_airflow_context_varsin- airflow_local_settings.pyfile.
For example:
In your airflow_local_settings.py file.
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"}
