如何从 VS Code 连接 SageMaker notebook?

Tim*_*ila 7 amazon-web-services visual-studio-code

我正在使用 SageMaker 来测试 ML 方法。我想将我的 SageMaker 脚本重构为更适合生产的代码。因此,我想像以前一样使用 VS Code 重构代码并在 SageMaker 实例上运行代码。VS Code Python 让你定义:

Python:指定 Jupyter 服务器 URI

SageMaker 通过运行为您提供 AuthorizedUrl

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

当我在隐身浏览器中打开它时 AuthorizedUrl 工作。为什么它不适用于 VS Code?VS Code 询问密码。我在没有帮助的情况下尝试了多种方法:

  1. 空密码,因为它在 SageMaker 的 jupyter_notebook_config.py 中为空
  2. 令牌作为密码 [1]
  3. 我设置了一个密码“jupyter notebook password”并重新启动了jupyter“sudo initctl restart jupyter-server --no-wait”。新密码似乎有效。我为 VS Code 提供了新创建的密码,但结果同样糟糕。

VS Code 给了我这个错误:

无法连接到远程 Jupyter 笔记本。检查 Jupyter 服务器 URI 设置是否指定了有效的运行服务器...错误:无法连接到受密码保护的服务器。检查密码是否正确。

那么如何在 SageMaker 上的 VS Code 中运行代码?也许有比我正在尝试的更好的方法?

谢谢

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

小智 0

据我了解,您希望在 VS Code 中连接来自 Sagemaker Studio Lab 的 jupyter-lab/notebooks。我还想在我的项目中使用 VS Code,并且以下步骤对我有用。

  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. 复制您的工作室实验室 URL 并将其粘贴到新选项卡中。URL 如下所示https://xxxxxxxxxxx.studio.us-east-2.sagemaker.aws/studiolab/default/jupyter/lab/
  4. 将实验室替换为proxy/8080。URL 变为https://xxxxxxxxxxxx.studio.us-east-2.sagemaker.aws/studiolab/default/jupyter/proxy/8080/
  5. 给它几分钟(大约 3 分钟)来加载。StudioLab 中的 Boom VS Code。

这是我对 stackexchange 的第一个贡献,如果有帮助的话请点赞。