Passing Environment Variables to Workload at Launch¶
This example demonstrates how to pass environment variables to a workload at launch.
Requirements¶
- A running Orion instance
- Orion API Key
kuiperrole assigned to the user running the script
Script¶
Warning
If you get a requests.exceptions.SSLError you can pass in the verify=False parameter to the request to disable SSL verification.
Custom environment variables passed at launch
import os
import requests
server = os.environ["SERVER"]
token = os.environ["TOKEN"]
custom_var = os.environ["CUSTOM_VAR"]
user = os.environ["USER"]
idx = os.environ["IDX"]
# Create a new workload
rsp = requests.post(
f"{server}/kuiper/request",
headers={"Authorization": token},
json={"instance_type": idx, "user": user, "env": {"CUSTOM_VAR": custom_var}},
verify=False,
)
$ export TOKEN="your-token"
$ export SERVER="https://orion-install"
$ export IDX="go"
$ export CUSTOM_VAR="Hello, World!"
$ export USER="my-user"
$ python custom_var.py
---> 100%
This script will create a workload with a custom environment variable CUSTOM_VAR set to Hello, World!.
Verification¶
We can verify this by running env inside of a workload terminal.