Survey banner
The Dataiku Community is moving to a new home! Some short term disruption starting next week: LEARN MORE

Can a python script API know which infra it is deployed on?

Antal
Can a python script API know which infra it is deployed on?

I'm deploying a python script API that will communicate with another (external) API, made by another department.

Both my team and the other team use separate Test/Acceptance/Production environments.

The url of the other team's API will change depending on the environment it is deployed in.

I'd like to change the url to call from within my Dataiku API depending on the current environment/infra, so both the DS API and the external API can match up through the delivery environments.

Is it possible for a python script API to somehow know which infra it's currently deployed in (through the python public API)? That way I could set up a mapping to the external url to call.


Operating system used: Windows

0 Kudos
3 Replies
AlexT
Dataiker

Hi,
The infra ID is not available from the API endpoint, but you can set you own env variables if these are static API nodes and retrieve via code:

import os

# get the value of a specific environment variable
env_var_value = os.environ.get("ENV_VAR_NAME")

Thanks

0 Kudos
Antal
Author

Thanks @AlexT 

I figured something along those lines.

Where and how would I set those environment variables as global for an API node?

0 Kudos
AlexT
Dataiker

Hi,
For Static API nodes, you can include this in the DATADIR/bin/env-site.sh 
by adding a line like : 

export APINODE_INFRA_ID='your_infra_id'

Thanks

0 Kudos

Labels

?
Labels (2)

Setup info

?
A banner prompting to get Dataiku