Skip to content

Environment Variables

'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.

Create an environment variable

Start by going to a deployment in the UbiOps WebApp. Click on the Advanced tab and then the Create variable icon. You can now create an environment variable by filling in its name and value.

Handling Secrets

You can set the environment variable to secret during creation. In this way, the value will not show up in API responses or logs. Use this when you have sensitive information like passwords in your environment variable.

Copy environment variables

Alternatively, environment variables can also be created by copying over existing variables from a deployment or 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. Also 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 Python deployment code. See the example below for accessing the variable named MY_VARIABLE.

import os

variable = os.environ['MY_VARIABLE']

print(variable)
For more information, take a look at the python documentation page.

Predefined environment variables

A couple of environment variable names are reserved for special functionality.

Variable name Function
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'.