Adding environment variables to notebooks

Any notebook user can add environment variables to their own notebooks.

Before you begin

  • You must be a cluster administrator, consumer administrator, or owner of the notebook with the Data Scientist or Consumer User role to add environment variables to your notebooks.
  • The notebook must be stopped before adding environment variables to it. For more information, see Stopping notebooks in an instance group.

About this task

A notebook's service activity scripts take the values provided in your environment variables to complete actions. For example, for notebooks enabled with Kerberos user authentication and service-level user impersonation, you require specifying your principal and keytab file (as the file is unique to each user), so that the system can then use this information when starting a Kerberos authenticated notebook using a service-level user impersonation user.

When adding environment variables , if the same environment variable name has been defined in the notebook, the user-defined value will be used.

Notebook users can add this environment variable to the notebooks that they own, and the notebook user's value takes precedence if the same environment variable name is defined elsewhere. For details about precedence of notebook environment variable values, see Jupyter notebook environment variables

Procedure

  1. From the cluster management console, click Workload > Instance Groups.
  2. Click the instance group associated with your notebook to open it for editing, and then click the Notebooks tab.
  3. Select the notebook to which you want to add environment variables, and click Configure.
  4. Click Add a variable, specify the environment variable name and value, and click Save.

    For a list of supported built-in Jupyter notebook environment variables names, see Jupyter notebook environment variables.

    For example, for built-in Jupyter notebooks enabled with Kerberos user authentication and service-level user impersonation, the system requires your principal and the location of your keytab file for your notebook. In this case, use this cluster management console page to add the JUPYTER_USER_SPARK_OPTS environment variable with values for the spark.yarn.principal and spark.yarn.keytab Kerberos parameters in this format:
    --conf spark.yarn.principal=user@realm --conf spark.yarn.keytab=/path_to_user.keytab
    Here is an example:
    JUPYTER_USER_SPARK_OPTS = "--conf spark.yarn.principal=jsmith@example.com --conf spark.yarn.keytab=/home/mykeytabdirectory/jsmith.keytab"

    For all other (non built-in) notebooks, use an environment variable that is understood by your notebook start scripts to define the Spark spark.yarn.principal and spark.yarn.keytab parameters for your notebook kernel. Specific environment variable names will differ depending on your notebook implementation.

Results

The environment variable is added to the specified notebook.

What to do next

Restart your notebook. For more information, see Starting notebooks in an instance group.