Amazon SageMaker AI の Jupyter UI でダウンロード機能を無効化したいです。
解決策
SageMaker AI がホストする Jupyter ノートブックでダウンロード機能を無効にするには、ターゲットリソースタイプ用のライフサイクル設定スクリプトを作成します。次のコード例よりいずれかを [スクリプト] セクションに入力します。
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 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 を選択します。
SageMaker AI Studio JupyterLab スペース
jupyter labextension disable @jupyterlab/docmanager-extension:download
jupyter labextension disable @jupyterlab/filebrowser-extension:download
設定を作成した後、リソースにライフサイクル設定をアタッチします。次に、ターゲットリソースを起動します。
関連情報
LCC スクリプトを使用して SageMaker AI ノートブックインスタンスをカスタマイズする