16

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

Timo Nikkila
  • 161
  • 1
  • 3
  • 2
    Hi, did you ever figure this out? – Austin Mar 23 '20 at 00:40
  • 1
    I did not find solution. – Timo Nikkila Mar 28 '20 at 07:36
  • 5
    You can get a step further by changing "authToken" to "token" in the pre-signed URL which stops the password from being required, but then you run into another error. It seems that AWS is doing some additional security stuff than normal notebooks, which VS Code doesn't support yet. This is tracked [in this issue](https://github.com/microsoft/vscode-python/issues/11002). – marcusturewicz Jun 04 '20 at 05:10
  • 1
    Thanks Marcus for the link to the issue! – Timo Nikkila Jun 05 '20 at 08:48

1 Answers1

0

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.

  • Is xxxxx representing a random string of characters? I'm wondering if this is secure. If a hacker guesses your notebook url they could get access to your notebook. – Almenon Dec 16 '22 at 23:18