I am using the AWS Sagemaker notebook instances for some of my experiments. As I am also using the lifecycle configurations scripts that are executed during notebook startup and also want to set some environment variables.
For some reason, when I set multiple env variables in the lifecycle shell script, they are not set by the instance, i.e. when I execute
echo $FOO
the relevant variable is not printed.
However, when I set only one env variable it is working and I can use it in my notebook session.
My understanding is that I start the desired Kernel,
I have also tried to set the env variables inside the notebook by running export FOO=BAR but that also did not work.
Following the example script provided by AWS, I made my changes to set the variables, however when I print $FOO, it doesn't seem to be displayed.
I have tried setting the envs before and after switching to ec2-user (before the commands are executed as root), still nothing helped.
#!/bin/bash
cd /home/ec2-user/anaconda3/envs/python3
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d
touch ./etc/conda/activate.d/env_vars.sh
touch ./etc/conda/deactivate.d/env_vars.sh
echo export FOO=BAR >> ./etc/conda/activate.d/env_vars.sh
echo unset FOO >> ./etc/conda/deactivate.d/env_vars.sh
echo export FOO2=BAR2 >> ./etc/conda/activate.d/env_vars.sh
echo unset FOO2 >> ./etc/conda/deactivate.d/env_vars.sh
sudo -u ec2-user -i <<'EOF'
cd /home/ec2-user
# This will affect only the Jupyter kernel called "conda_python3".
source activate python3
pip install --upgrade pip
pip install scipy xgboost sklearn
# You can also perform "conda install" here as well.
source deactivate
EOF
I want to set multiple environment variables for this Sagemaker notebook upon start, what is the best way to do this?