I am trying to set some environment variables for a user managed notebook in google cloud Vertex AI. I don't want to set this from a jupyter notebook itself because I want these environment variables to be available to anyone who opens a jupyter notebook from this notebook instance. This is what I have tried so far but nothing has worked:
- I have an existing user managed notebook. I ssh'd into the notebook vm and then set a environment variable,
export TEST_VAR=TEST_VARIABLE_WAS_SET
there. However, when I open a jupyter notebook from the console and doos.environ["TEST_VAR"]
, it gives a key error. So, I am assuming that this has something to do with the fact that the jupyter lab session that Vertex AI starts is in a different shell session or something similar. I also tried to add the following two metadata keys to the vm, and then restarted the vm, but it did not work:
gcloud compute instances add-metadata ${INSTANCE_NAME} --metadata startup-script-url=$GCS_BUCKET_NAME/script.sh
where script.sh is:
#!/bin/bash
export TEST_VAR=TEST_VARIABLE_WAS_SET
AND
gcloud compute instances add-metadata ${INSTANCE_NAME} --metadata container-env-file=$GCS_BUCKET_NAME/notebook-env.txt
where notebook-env.txt is
TEST_VAR=TEST_VARIABLE_WAS_SET
- I also tried to create a new instance of a user managed notebook from the cloud console. In that I tried to provide a script in the "Select a script to run after creation" and also through the "Metadata" option by providing, the key as
startup-script-url
and the value as the script location on google cloud storage. The script was the same startup script earlier.
So, how do I achieve this, for existing user managed notebooks and when I create new ones?