跳至內容

如何關閉 SageMaker AI 中 Jupyter UI 中的下載功能?

1 分的閱讀內容
0

我想關閉 Amazon SageMaker AI 中 Jupyter UI 的下載功能。

解決方法

若要關閉 SageMaker AI 所託管 Jupyter 筆記本中的下載功能,請為目標資源類型建立生命週期組態指令碼。在 Scripts (指令碼) 區段中,輸入下列其中一個程式碼範例。

SageMaker AI 筆記本執行個體:

cat <<END >>/home/ec2-user/.jupyter/handlers.py
from tornado import web
from notebook.base.handlers import IPythonHandler

class ForbidFilesHandler(IPythonHandler):
  @web.authenticated
  def head(self, path):
    self.log.info("HEAD: File download forbidden.")
    raise web.HTTPError(403)

  @web.authenticated
  def get(self, path, include_body=True):
    self.log.info("GET: File download forbidden.")
    raise web.HTTPError(403)

END

cat <<END >>/home/ec2-user/.jupyter/jupyter_notebook_config.py
import os, sys
sys.path.append('/home/ec2-user/.jupyter/')
import handlers
c.ContentsManager.files_handler_class = 'handlers.ForbidFilesHandler'
c.ContentsManager.files_handler_params = {}

END

reboot

**注意:**在 SageMaker AI 筆記本執行個體中,請在 Start Notebook (啟動筆記本) 編輯器中輸入您的指令碼。

SageMaker AI Studio 經典版:

__conda_setup="$('/opt/conda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/conda/etc/profile.d/conda.sh" ]; then
        . "/opt/conda/etc/profile.d/conda.sh"
    else
        export PATH="/opt/conda/bin:$PATH"
    fi
fi
unset __conda_setup

conda activate studio
jupyter labextension disable @jupyterlab/docmanager-extension:download
jupyter labextension disable @jupyterlab/filebrowser-extension:download
restart-jupyter-server

**注意:**新增指令碼時,請選取 JupyterServer App

SageMaker AI Studio JupyterLab空間:

jupyter labextension disable @jupyterlab/docmanager-extension:download
jupyter labextension disable @jupyterlab/filebrowser-extension:download

建立組態之後,將生命週期組態附加到您的資源。然後,啟動您的目標資源

相關資訊

使用 LCC 指令碼自訂 SageMaker AI 筆記本執行個體

AWS 官方已更新 1 年前