To install Jupyter Lab Extension on AWS sagemaker, You need to follow https://github.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/tree/master/scripts. And then create the lifecycle configuration accordingly.
I did it and this is my on-start.sh
file.
#!/bin/bash
set -e
# OVERVIEW
# This script installs a jupyterlab extension package in SageMaker Notebook Instance
sudo -u ec2-user -i <<'EOF'
# PARAMETERS
EXTENSION_NAME=@jupyter-widgets/jupyterlab-manager
source /home/ec2-user/anaconda3/bin/activate JupyterSystemEnv
jupyter labextension install $EXTENSION_NAME
source /home/ec2-user/anaconda3/bin/deactivate
EOF
Everything should went smooth except for this extension it raises an error.
This is the error log from cloud watch.
/bin/bash: /tmp/OnStart_2019-06-26-23-3260vo0j6p: /bin/bash^M: bad interpreter: No such file or directory
This one is the error message shown in the sagemaker console.
Failure reason
Notebook Instance Lifecycle Config 'arn:aws:sagemaker:ap-southeast-1:658055165324:notebook-instance-lifecycle-config/jupyter-widgets-for-jupyterlab-copy' for Notebook Instance 'arn:aws:sagemaker:ap-southeast-1:658055165324:notebook-instance/test' took longer than 5 minutes. Please check your CloudWatch logs for more details if your Notebook Instance has Internet access.
I had done several attempts to locate the bug in the script file and the setup file of ipywidgets
concerning the 'bad interpreter' error. I cannot find any traces of error in both.
I tried to upgrade my instance to T2 largest instance just in case the error came from the timeout.
The weirdest thing is that I am able to install it via the terminal from the terminal on jupyterlab. I measured the total time it takes to install and found it is around 4 mins
just enough time(AWS should allow more time since this is only one extension install). Noted that this installation was performed under the T2 medium instance(the cheapest instance type you could get). If you install it this way to have to reboot the jupyter lab to make it work, then you reboot your instance and everything reverts back to the not-yet-install state. This suggests that there is no way to install jupyter lab extension rather than using the lifecycle cycle configurations which will lead you back to the error.
At this point, I gave up and use the jupyter notebook instead if I really want to use the ipywidgets
.
Normally, this should be raised as technical support on AWS, but I have the basic plan so I decided to file it in StackOverflow for others that might encounter the same thing.