Project Environment Variables

Sometimes your code needs to use secrets, such as passwords and authentication tokens, in order to access external resources.

In general, Cloudera recommends that you not paste secrets into your code. Anyone with read access to your project would be able to view the secrets. Even if you did not give anyone read access, you would have to remember to carefully check any code that you copy and paste into another project, or add to a Git repository.

A better place to store secrets is in your project's environment variables, which you can manage by going to the project's Overview page and from the left sidebar, click Settings > Engine.

These environment variables are set in every engine that runs in your project. The code samples that follow show how to access the environment variable DATABASE_PASSWORD from your code.

R

database.password <- Sys.getenv("DATABASE_PASSWORD")

Python

import os
database_password = os.environ["DATABASE_PASSWORD"]

Scala

System.getenv("DATABASE_PASSWORD")

Engine Environment Variables

The following table lists environment variables that can be set by default in every engine.

Environment Variable Description
CDSW_PROJECT

The project to which this engine belongs.

CDSW_CREATOR

The username of the creator of this engine.

CDSW_ENGINE_ID

The ID of this engine. For sessions, this appears in your browser's URL bar.

CDSW_MASTER_ID

If this engine is a worker, this is the CDSW_ENGINE_ID of its master.

CDSW_MASTER_IP

If this engine is a worker, this is the IP address of its master.

CDSW_PUBLIC_PORT

A port on which you can expose HTTP services in the engine to users' browsers. HTTP services that bind CDSW_PUBLIC_PORT will be available in users' browsers at: http(s)://<$CDSW_ENGINE_ID>.<$CDSW_DOMAIN>.

CDSW_DOMAIN

The domain on which Cloudera Data Science Workbench is being served. This can be useful for iframing services, as in the Shiny example.

CDSW_CPU_MILLICORES

The number of CPU cores allocated to this engine, expressed in thousandths of a core.

CDSW_MEMORY_MB

The number of megabytes of memory allocated to this engine.

CDSW_IP_ADDRESS

Other engines in the Cloudera Data Science Workbench cluster can contact this engine on this IP address.