Environment variables are variables inside your deployment code that are set and managed through UbiOps. They can be useful for secure handling of credentials which you don't want to have hardcoded inside your deployment package, but also for parameters that you want to control or change without uploading a new deployment package file.
Environment variables can be defined on 3 different levels: project, deployment and deployment versions.
Project variables are shared between all deployment versions in a project.
Deployment variables are shared between all deployment versions of a deployment. If a variable with the same name of a project variable is defined as a deployment variable, the value will be overwritten by the deployment variable.
Deployment version variables are specific to the deployment version. If a variable with the same name of a project or deployment variable is defined as a deployment variable, the value will be overwritten by the deployment version variable.
Create an environment variable¶
To create a deployment level environment variable, go to a deployment in the UbiOps WebApp. Click on the Environment variables tab and then the Create variable icon. You can now create an environment variable by filling in its name and value.
You can create a deployment version level environment variable in the same way by going to Environment variables tab in a specific deployment version page.
Marking environment variables as secret
You can mark an environment variable as secret during creation. The value of a secret variable cannot be obtained via the API or WebApp after it is created, and will not be included in exports. This can be useful to protect passwords and other sensitive information.
Copy environment variables¶
Alternatively, environment variables can also be created by copying over existing variables from a deployment or deployment version. Click on the Copy existing variables button next to the Create variable icon and select the source object which you would like to copy from. If the source object is a deployment, leave the 'Source version' field empty. All existing environment variables with the same name will be overwritten. Note that you need permissions to list the environment variables of the source object.
Using an environment variable¶
After creating the environment variable, you can use it in your deployment code. See the example below for accessing the variable named
import os variable = os.environ['MY_VARIABLE'] print(variable)
For more information, take a look at the Python documentation page.
variable <- Sys.getenv("MY_VARIABLE") print(variable)
For more information, take a look at the R documentation page.
Predefined environment variables¶
A couple of environment variable names are reserved for special functionality.
|SYS_DEPLOYMENT_FILE_NAME||Sets a custom name for the file that contains the deployment class and request method. Defaults to 'deployment.py'.|
|SYS_DEPLOYMENT_CLASS_NAME||Sets a custom name for the class in the deployment file that contains the request method. Defaults to 'Deployment'.|
|SYS_DEFAULT_BUCKET||Specifies what bucket you want to set as the default bucket to read and write from during request or training run handling. Defaults to |