21

I am using SageMaker to test ML approaches. I would like to refactor my SageMaker scripts towards more production ready code. Thus I would like to use VS Code to refactor code and run code on SageMaker instance as before. VS Code Python lets you define:

Python: Specify Jupyter Server URI

SageMaker gives you AuthorizedUrl by running

aws sagemaker create-presigned-notebook-instance-url --notebook-instance-name your-instance-name

AuthorizedUrl works when I open it in incognito browser. Why it does not work with VS Code? VS Code asks password. I tried multiple approaches with no help:

  1. empty password since it is empty in SageMaker's jupyter_notebook_config.py
  2. token as password [1]
  3. I set a password "jupyter notebook password" and restarted jupyter "sudo initctl restart jupyter-server --no-wait". New password seemed to be effective. I gave newly created password to VS Code with same poor results.

VS Code gives me this error:

Failed to connect to remote Jupyter notebook. Check that the Jupyter Server URI setting has a valid running server specified... Error: Failed to connect to password protected server. Check that password is correct.

So how can I run codes in VS Code on SageMaker? Maybe there is better way than what I am trying?

Thanks

[1] https://jupyter-notebook.readthedocs.io/en/stable/security.html

1 Answers1

3

As I understand you want to connect your jupyter-lab/notebooks from Sagemaker Studio Lab in VS Code. I also want to use VS Code for my project and the below steps worked for me.

  1. (studiolab) studio-lab-user@default:~$ conda install -y -c conda-forge code-server
  2. (studiolab) studio-lab-user@default:~$ code-server --auth none
  3. Copy your studio lab url and paste it in a new tab. URL looks like this https://xxxxxxxxxxx.studio.us-east-2.sagemaker.aws/studiolab/default/jupyter/lab/
  4. Replace the lab with proxy/8080. The URL becomes https://xxxxxxxxxxxx.studio.us-east-2.sagemaker.aws/studiolab/default/jupyter/proxy/8080/
  5. Give it a few minutes(around ~3min) to load. Boom VS Code in your StudioLab.

This is my first contribution to stackexchange, Upvote if it helps.