Ich möchte die Download-Funktion in der Jupyter-Benutzeroberfläche in Amazon-SageMaker-KI ausschalten.
Lösung
Um die Download-Funktion in von SageMaker KI gehosteten Jupyter-Notebooks auszuschalten, erstelle ein Lebenszykluskonfigurationsskript für den Zielressourcentyp. Gib im Abschnitt Skripte eines der folgenden Codebeispiele ein.
SageMaker-KI-Notebook-Instance:
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
Hinweis: Gib für SageMaker-KI-Notebook-Instances das Skript im Start Notebook-Editor ein.
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
Hinweis: Wenn du das Skript hinzufügst, wähle JupyterServer-App aus.
Die JupyterLab-Umgebung von SageMaker AI Studio:
jupyter labextension disable @jupyterlab/docmanager-extension:download
jupyter labextension disable @jupyterlab/filebrowser-extension:download
Nachdem du die Konfiguration erstellt hast, hänge die Lebenszykluskonfiguration an die Ressource an. Starte dann die Zielressource.
Ähnliche Informationen
Anpassung einer SageMaker-KI-Notebook-Instance mithilfe eines LCC-Skripts