Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access Airflow variables and parameters passed via REST API #121

Open
bodhwani opened this issue Jan 12, 2022 · 2 comments
Open

How to access Airflow variables and parameters passed via REST API #121

bodhwani opened this issue Jan 12, 2022 · 2 comments

Comments

@bodhwani
Copy link

I have a use case where I am accessing Airflow's variable using Variable.get(). How can I achieve this in yaml file.

Also, how can I access parameters (params.app_name, params.namespace etc) which I am passing via REST API as follows:

{ "conf": { "app_name":"app namet", "region":"", "namespace": "", "default_path": "", } }

env_variables = Variable.get("env_variables", deserialize_json=True)
fetch_yaml = BashOperator(
        bash_command="export {{var.json.env_variables['kube_config'] && kubectl get sparkapplications {{ params.app_name}} -n {{params.namespace}}",
        task_id="fetch_yaml"
    )
@aramakrishnan19
Copy link
Contributor

aramakrishnan19 commented Feb 2, 2022

Airflow variables can be accessed as below

within yaml specify any attribute with the value as shown below. Note the quotes, some of them are two single quotes.
ENV: '{{ var.value.get(''ENVIRONMENT'', ''no-mans-land'') }}'

I am also looking at how to access params though, which is typically as

DAG(params={...}), however specifying these with in yaml does not resolve.

YAML

params:
    key: value

comes out as below when printing ... print(vars(context.get('dag')))

'params': {}

Reference : https://github.com/apache/airflow/blob/main/airflow/models/dag.py#L229

@aramakrishnan19
Copy link
Contributor

PR submitted.

#124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants