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 노트북 인스턴스의 경우 노트북 시작 편집기에 스크립트를 입력합니다.
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 앱을 선택합니다.
SageMaker AI Studio JupyterLab space:
jupyter labextension disable @jupyterlab/docmanager-extension:download
jupyter labextension disable @jupyterlab/filebrowser-extension:download
구성을 생성한 후 리소스에 수명 주기 구성을 연결합니다. 그런 다음 대상 리소스를 시작합니다.
관련 정보
LCC 스크립트를 사용한 SageMaker AI 노트북 인스턴스 사용자 지정