我想关闭 Amazon SageMaker 人工智能中 Jupyter UI 中的下载功能。
解决方法
要关闭 SageMaker 人工智能托管的 Jupyter Notebook 中的下载功能,请为您的目标资源类型创建生命周期配置脚本。在 Scripts(脚本)部分中,输入以下代码示例之一。
SageMaker 人工智能 Notebook 实例:
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 人工智能 Notebook 实例,请在 Start Notebook(启动 Notebook)编辑器中输入您的脚本。
SageMaker 人工智能 Studio Classic:
__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(JupyterServer 应用程序)。
SageMaker 人工智能 Studio JupyterLab 空间:
jupyter labextension disable @jupyterlab/docmanager-extension:download
jupyter labextension disable @jupyterlab/filebrowser-extension:download
创建配置后,将生命周期配置附加到您的资源。然后,启动您的目标资源。
相关信息
使用 LCC 脚本自定义 SageMaker 人工智能 Notebook 实例