

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# SageMaker JupyterLab
<a name="studio-updated-jl"></a>

在 Amazon SageMaker Studio 中创建一个 JupyterLab 空间来启动 JupyterLab应用程序。 JupyterLab 空间是 Studio 中的私有或共享空间，用于管理运行 JupyterLab 应用程序所需的存储和计算资源。该 JupyterLab 应用程序是一个基于 Web 的交互式开发环境 (IDE)，用于笔记本电脑、代码和数据。使用该 JupyterLab 应用程序灵活而广泛的界面来配置和安排机器学习 (ML) 工作流程。

默认情况下， JupyterLab 应用程序附带 SageMaker 分发镜像。发行版映像包含以下常用软件包：
+ PyTorch
+ TensorFlow
+ Keras
+ NumPy
+ Pandas
+ Scikit-learn

您可以使用共享空间与其他用户实时协作编写 Jupyter Notebook。有关共享空间的更多信息，请参阅[使用共享空间进行协作](domain-space.md)。

在 JupyterLab 应用程序中，您可以使用 Amazon Q Developer（一款生成式 AI 驱动的代码伴侣）来生成、调试和解释您的代码。有关使用 Amazon Q 开发者版的信息，请参阅 [JupyterLab 用户指南](studio-updated-jl-user-guide.md)。有关设置 Amazon Q 开发者版的信息，请参阅 [JupyterLab 管理员指南](studio-updated-jl-admin-guide.md)。

在同一个 Jupyter Notebook 中构建统一的分析和 ML 工作流程。直接在笔记本上在 Amazon EMR 和 AWS Glue 无服务器基础设施上运行交互式Spark作业。使用内联 Spark 用户界面更快地监控和调试作业。只需几步，您就可以将笔记本作为一项作业进行调度，从而实现数据准备的自动化。

该 JupyterLab 应用程序可帮助您与同行协作。使用 JupyterLab IDE 中内置的 Git 集成来共享和版本代码。如果您有 Amazon EFS 卷，请自带文件存储系统。

该 JupyterLab 应用程序在单个亚马逊弹性计算云 (Amazon EC2) 实例上运行，并使用单个亚马逊弹性区块存储 (Amazon EBS) 卷进行存储。您可以根据需要切换速度更快的实例或增加 Amazon EBS 卷的大小。

 JupyterLab 4 应用程序在 Studio 的某个 JupyterLab 空间中运行。Studio Classic 使用 JupyterLab 3 应用程序。 JupyterLab 4 提供以下好处：
+ 比 Amazon SageMaker Studio Classic 更快的 IDE，尤其是对于大型笔记本电脑
+ 改进文件搜索
+ 性能更强、更易于使用的文本编辑器

有关的更多信息 JupyterLab，请参阅[JupyterLab文档](https://jupyterlab.readthedocs.io/en/stable/#)。

**Topics**
+ [JupyterLab 用户指南](studio-updated-jl-user-guide.md)
+ [JupyterLab 管理员指南](studio-updated-jl-admin-guide.md)

# JupyterLab 用户指南
<a name="studio-updated-jl-user-guide"></a>

本指南向 JupyterLab 用户展示了如何在 SageMaker Studio 中运行分析和机器学习工作流程。您可以获得快速存储，并根据自己的需要扩大或缩小计算规模。

JupyterLab 支持私有空间和共享空间。专用空间的作用域为域中的单个用户。共享空间可让域内其他用户与您实时协作。有关 Studio 空间的信息，请参阅 [亚马逊 SageMaker Studio 空间](studio-updated-spaces.md)。

要开始使用 JupyterLab，请创建一个空间并启动您的 JupyterLab应用程序。运行 JupyterLab 应用程序的 JupyterLab 空间是一个空间。该 JupyterLab 空间使用单个 Amazon EC2 实例进行计算，使用单个 Amazon EBS 卷进行存储。您空间中的所有内容，如代码、git 配置文件和环境变量，都存储在同一个 Amazon EBS 卷上。该卷具有 3000 IOPS，吞吐量为每秒 125 兆字节 ()。MBps您可以使用快速存储在同一实例上打开和运行多个 Jupyter Notebook。您还可以在笔记本中快速切换内核。

您的管理员已为您的空间配置了默认 Amazon EBS 存储设置。默认存储容量为 5 GB，但您可以增加获得的空间。您可以向管理员咨询，他们会为您提供指导。

您可以切换用于运行的 Amazon EC2 实例类型 JupyterLab，根据需要向上或向下扩展计算规模。**快速启动**实例的启动速度比其他实例快得多。

管理员可能会为您提供可自定义环境的生命周期配置。您可以在创建空间时指定生命周期配置。

如果您的管理员授予您访问 Amazon EFS 的权限，则可以配置您的 JupyterLab空间来访问它。

默认情况下， JupyterLab 应用程序使用 SageMaker 分发映像。这包括对许多机器学习、分析和深度学习软件包的支持。不过，如果您需要自定义映像，您的管理员可以帮助您访问自定义映像。

Amazon EBS 卷的持久性与实例的生命周期无关。您在更换实例时不会丢失数据。使用 conda 和 pip 软件包管理库创建可重现的自定义环境，即使切换实例类型也能保持不变。

打开后 JupyterLab，您可以使用终端配置您的环境。要打开终端，请导航至**启动器**，然后选择**终端**。

以下是您可以在中配置环境的不同方法的示例 JupyterLab。

**注意**  
在 Studio 中，您可以使用生命周期配置来自定义环境，但我们建议您使用软件包管理器。使用生命周期配置是一种更容易出错的方法。添加或删除依赖关系比调试生命周期配置脚本更容易。它还可以增加 JupyterLab 启动时间。  
有关生命周期配置的信息，请参阅 [生命周期配置 JupyterLab](jl-lcc.md)。

**Topics**
+ [创建空间](studio-updated-jl-user-guide-create-space.md)
+ [配置空间](studio-updated-jl-user-guide-configure-space.md)
+ [使用软件包管理器自定义环境](studio-updated-jl-user-guide-customize-package-manager.md)
+ [清理 conda 环境](studio-updated-jl-clean-up-conda.md)
+ [在实例类型之间共享 conda 环境](studio-updated-jl-create-conda-share-environment.md)
+ [使用 Amazon Q 加快机器学习工作流程](studio-updated-jl-user-guide-use-amazon-q.md)

# 创建空间
<a name="studio-updated-jl-user-guide-create-space"></a>

要开始使用 JupyterLab，请创建一个空间或选择管理员为您创建的空间并打开 JupyterLab。

使用以下步骤创建空间并打开 JupyterLab。

**创建空间并打开 JupyterLab**

1. 打开 Studio。有关打开 Studio 的信息，请参阅 [启动亚马逊 SageMaker Studio](studio-updated-launch.md)。

1. 选择 **JupyterLab**。

1. 选择 “**创建 JupyterLab 空间**”。

1. 对于**名称**，请指定空间的名称。

1. (可选）选择**与我的域共享**以创建共享空间。

1. 选择**创建空间**。

1. (可选）对于**实例**，指定运行空间的 Amazon EC2 实例。

1. (可选）对于**映像**，请指定管理员提供的映像，以自定义环境。
**重要**  
允许 Studio 用户创建空间的自定义 IAM 策略还必须授予列出映像 (`sagemaker: ListImage`) 的权限，以便查看自定义映像。要添加权限，请参阅《AWS Identity and Access Management用户指南》**中的[添加或移除身份权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。  
[AWS 亚马逊 A SageMaker I 的托管策略](security-iam-awsmanpol.md)授予创建 SageMaker AI 资源的权限已经包括在创建这些资源时列出图像的权限。

1. (可选）对于**空间设置**，请指定以下内容：
   + **存储空间（GB）**：最大 100 GB 或管理员指定的容量。
   + **生命周期配置**：管理员指定的生命周期配置。
   + **附加自定义 EFS 文件系统**：您的管理员可访问的 Amazon EFS。

1. 选择**运行空间**。

1. 选择**打开 JupyterLab**。

# 配置空间
<a name="studio-updated-jl-user-guide-configure-space"></a>

创建 JupyterLab 空间后，您可以将其配置为执行以下操作：
+ 更改实例类型。
+ 更改存储容量。
+ （需要管理员设置）使用自定义映像。
+ （需要管理员设置）使用生命周期配置。
+ （需要管理员设置）附加自定义 Amazon EFS。

**重要**  
每次配置 JupyterLab 空间时都必须将其停止。使用以下步骤配置空间。

**配置空间**

1. 在 Studio 中，导航到 JupyterLab 应用程序页面。

1. 选择空间名称。

1. (可选）对于**映像**，请指定管理员提供的映像，以自定义环境。
**重要**  
允许 Studio 用户创建空间的自定义 IAM 策略还必须授予列出映像 (`sagemaker: ListImage`) 的权限，以便查看自定义映像。要添加权限，请参阅《AWS Identity and Access Management用户指南》**中的[添加或移除身份权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。  
[AWS 亚马逊 A SageMaker I 的托管策略](security-iam-awsmanpol.md)授予创建 SageMaker AI 资源的权限已经包括在创建这些资源时列出图像的权限。

1. (可选）对于**空间设置**，请指定以下内容：
   + **存储空间（GB）**：最高 100 GB 或管理员为空间配置的容量。
   + **生命周期配置**：管理员提供的生命周期配置。
   + **附加自定义 EFS 文件系统**：您的管理员可访问的 Amazon EFS。

1. 选择**运行空间**。

当您打开 JupyterLab 应用程序时，您的空间的配置已更新。

# 使用软件包管理器自定义环境
<a name="studio-updated-jl-user-guide-customize-package-manager"></a>

使用 pip 或 conda 自定义环境。我们建议使用软件包管理器，而不是生命周期配置脚本。

## 创建并激活自定义环境
<a name="studio-updated-jl-create-basic-conda"></a>

本节提供了在中配置环境的不同方法的示例 JupyterLab。

基本的 conda 环境拥有 SageMaker AI 工作流程所需的最少软件包数量。使用以下模板创建基本的 conda 环境：

```
# initialize conda for shell interaction
conda init

# create a new fresh environment
conda create --name test-env

# check if your new environment is created successfully
conda info --envs

# activate the new environment
conda activate test-env

# install packages in your new conda environment
conda install pip boto3 pandas ipykernel

# list all packages install in your new environment 
conda list

# parse env name information from your new environment
export CURRENT_ENV_NAME=$(conda info | grep "active environment" | cut -d : -f 2 | tr -d ' ')

# register your new environment as Jupyter Kernel for execution 
python3 -m ipykernel install --user --name $CURRENT_ENV_NAME --display-name "user-env:($CURRENT_ENV_NAME)"

# to exit your new environment
conda deactivate
```

下图显示了您创建的环境的位置。

![\[test-env 环境显示在屏幕右上角。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/juptyer-notebook-environment-location.png)


要更改环境，请选择它，然后从下拉菜单中选择一个选项。

![\[复选标记及其相应文本显示的是您之前创建的示例环境。\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/jupyter-notebook-select-env.png)


选择**选择**为环境选择内核。

## 使用特定 Python 版本创建 conda 环境
<a name="studio-updated-jl-create-conda-version"></a>

清理不使用的 conda 环境有助于释放磁盘空间并提高性能。使用以下模板清理 conda 环境：

```
# create a conda environment with a specific python version
conda create --name py38-test-env python=3.8.10

# activate and test your new python version
conda activate py38-test-env & python3 --version

# Install ipykernel to facilicate env registration
conda install ipykernel

# parse env name information from your new environment
export CURRENT_ENV_NAME=$(conda info | grep "active environment" | cut -d : -f 2 | tr -d ' ')

# register your new environment as Jupyter Kernel for execution 
python3 -m ipykernel install --user --name $CURRENT_ENV_NAME --display-name "user-env:($CURRENT_ENV_NAME)"

# deactivate your py38 test environment
conda deactivate
```

## 创建带有特定软件包的 conda 环境
<a name="studio-updated-jl-create-conda-specific-packages"></a>

使用下面的模板创建带有特定 Python 版本和软件包集的 conda 环境：

```
# prefill your conda environment with a set of packages,
conda create --name py38-test-env python=3.8.10 pandas matplotlib=3.7 scipy ipykernel

# activate your conda environment and ensure these packages exist
conda activate py38-test-env

# check if these packages exist
conda list | grep -E 'pandas|matplotlib|scipy'

# parse env name information from your new environment
export CURRENT_ENV_NAME=$(conda info | grep "active environment" | cut -d : -f 2 | tr -d ' ')

# register your new environment as Jupyter Kernel for execution 
python3 -m ipykernel install --user --name $CURRENT_ENV_NAME --display-name "user-env:($CURRENT_ENV_NAME)"

# deactivate your conda environment
conda deactivate
```

## 从现有环境克隆 conda
<a name="studio-updated-jl-create-conda-clone"></a>

克隆您的 conda 环境，以保留其工作状态。您可以在克隆环境中进行实验，而不必担心在测试环境中引入破坏性更改。

使用以下命令克隆一个环境。

```
# create a fresh env from a base environment 
conda create --name py310-base-ext --clone base # replace 'base' with another env

# activate your conda environment and ensure these packages exist
conda activate py310-base-ext

# install ipykernel to register your env
conda install ipykernel

# parse env name information from your new environment
export CURRENT_ENV_NAME=$(conda info | grep "active environment" | cut -d : -f 2 | tr -d ' ')

# register your new environment as Jupyter Kernel for execution 
python3 -m ipykernel install --user --name $CURRENT_ENV_NAME --display-name "user-env:($CURRENT_ENV_NAME)"

# deactivate your conda environment
conda deactivate
```

## 从参考 YAML 文件克隆 conda
<a name="studio-updated-jl-create-conda-yaml"></a>

根据参考 YAML 文件创建 conda 环境。下面是一个可以使用的 YAML 文件示例。

```
# anatomy of a reference environment.yml
name: py311-new-env
channels:
  - conda-forge
dependencies:
  - python=3.11
  - numpy
  - pandas
  - scipy
  - matplotlib
  - pip
  - ipykernel
  - pip:
      - git+https://github.com/huggingface/transformers
```

在 `pip` 下，我们建议只指定 conda 不可用的依赖关系。

使用以下命令从 YAML 文件创建 conda 环境。

```
# create your conda environment 
conda env create -f environment.yml

# activate your env
conda activate py311-new-env
```

# 清理 conda 环境
<a name="studio-updated-jl-clean-up-conda"></a>

清理不使用的 conda 环境有助于释放磁盘空间并提高性能。使用以下模板清理 conda 环境：

```
# list your environments to select an environment to clean
conda info --envs # or conda info -e

# once you've selected your environment to purge
conda remove --name test-env --all

# run conda environment list to ensure the target environment is purged
conda info --envs # or conda info -e
```

# 在实例类型之间共享 conda 环境
<a name="studio-updated-jl-create-conda-share-environment"></a>

您可以将 conda 环境保存到 Amazon EBS 卷之外的 Amazon EFS 目录中，从而共享 conda 环境。其他用户可以访问您保存环境的目录。

**重要**  
共享环境有其局限性。例如，我们不推荐在 GPU Amazon EC2 实例上运行的环境，而推荐在 CPU 实例上运行的环境。

使用以下命令作为模板，指定创建自定义环境的目标目录。您正在特定路径内创建一个 conda。在 Amazon EFS 目录中创建。您可以启动一个新实例，在 Amazon EFS 中执行 conda 激活路径。

```
# if you know your environment path for your conda environment
conda create --prefix /home/sagemaker-user/my-project/py39-test python=3.9

# activate the env with full path from prefix
conda activate home/sagemaker-user/my-project/py39-test

# parse env name information from your new environment
export CURRENT_ENV_NAME=$(conda info | grep "active environment" | awk -F' : ' '{print $2}' | awk -F'/' '{print $NF}')

# register your new environment as Jupyter Kernel for execution 
python3 -m ipykernel install --user --name $CURRENT_ENV_NAME --display-name "user-env-prefix:($CURRENT_ENV_NAME)"

# deactivate your conda environment
conda deactivate
```

# 使用 Amazon Q 加快机器学习工作流程
<a name="studio-updated-jl-user-guide-use-amazon-q"></a>

Amazon Q 开发者版是您进行机器学习开发的人工智能驱动工具。使用 Amazon Q 开发者版，您可以：
+ 获取有关独立使用 SageMaker 人工智能功能或与其他 AWS 服务结合使用人工智能功能的 step-by-step指导。
+ 获取示例代码以开始执行机器学习任务，例如数据准备、训练、推理和 MLOps。
+ 接受故障排除帮助，以调试和解决运行代码时遇到的错误。

Amazon Q Developer 可以无缝集成到您的 JupyterLab 环境中。要使用 Amazon Q Develop **er**，请从您的 JupyterLab 环境或代码编辑器环境的左侧导航栏中选择 Q。

如果您没有看到 **Q** 图标，则需要管理员为您设置。有关设置 Amazon Q 开发者版的更多信息，请参阅 [为用户设置 Amazon Q 开发者版](studio-updated-amazon-q-admin-guide-set-up.md)。

Amazon Q 会自动提供建议，帮助您编写代码。您还可以通过聊天界面征求建议。

# JupyterLab 管理员指南
<a name="studio-updated-jl-admin-guide"></a>

**重要**  
允许 Amazon SageMaker Studio 或 Amazon SageMaker Studio Classic 创建亚马逊 SageMaker资源的自定义 IAM 策略还必须授予向这些资源添加标签的权限。之所以需要为资源添加标签的权限，是因为 Studio 和 Studio Classic 会自动为创建的任何资源添加标签。如果 IAM 策略允许 Studio 和 Studio Classic 创建资源但不允许标记，则在尝试创建资源时可能会出现 AccessDenied “” 错误。有关更多信息，请参阅 [提供标记 A SageMaker I 资源的权限](security_iam_id-based-policy-examples.md#grant-tagging-permissions)。  
[AWS 亚马逊 A SageMaker I 的托管策略](security-iam-awsmanpol.md)授予创建 SageMaker 资源的权限已经包括在创建这些资源时添加标签的权限。

本管理员指南描述了 SageMaker 人工智能 JupyterLab 资源，例如来自亚马逊弹性区块存储 (Amazon EBS) 和亚马逊弹性计算云 (Amazon EC2) 的资源。这些主题还展示介绍了如何提供用户访问权限和更改存储空间大小。

A SageMaker I JupyterLab 空间由以下资源组成：
+ 一个独立的 Amazon EBS 卷，用于存储所有数据，如代码和环境变量。
+ 用于运行空间的 Amazon EC2 实例。
+ 用于运行的图像 JupyterLab。

**注意**  
应用程序无法访问其他应用程序的 EBS 卷。例如，基于 Code-OSS、Visual Studio Code-Open Source 的代码编辑器无法访问的 EBS 卷。 JupyterLab有关 EBS 卷的更多信息，请参阅 [Amazon Elastic Block Store (Amazon EBS)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html)。

您可以使用 Amazon SageMaker API 执行以下操作：
+ 为用户更改 EBS 卷的默认存储空间大小。
+ 更改 EBS 存储空间的最大大小
+ 指定应用程序的用户设置。例如，您可以指定用户使用的是自定义映像还是存储库。
+ 指定支持应用程序类型。

Amazon EBS 卷的默认大小为 5 GB。您最多可以将卷大小增加到 16384 GB。如果您什么都不做，用户就可以将其卷大小增加到 100 GB。卷大小在六小时内只能更改一次。

与 JupyterLab 应用程序关联的内核在运行的同一 Amazon EC2 实例上运行 JupyterLab。创建空间时，默认使用最新版本的 SageMaker 分发映像。有关 SageMaker 分发映像的更多信息，请参阅[SageMaker 工作室图片支持政策](sagemaker-distribution.md)。

**重要**  
有关更新空间以使用最新版本的 SageMaker AI 分布映像的信息，请参阅[更新 SageMaker 分发映像](studio-updated-jl-update-distribution-image.md)。

存储卷内用户的工作目录是 `/home/sagemaker-user`。如果您指定自己的 AWS KMS 密钥来加密卷，则工作目录中的所有内容都将使用您的客户托管密钥进行加密。如果您未指定 AWS KMS 密钥，则使用 AWS 托管密钥对内部`/home/sagemaker-user`数据进行加密。无论您是否指定 AWS KMS 密钥，工作目录之外的所有数据都使用 AWS 托管密钥进行加密。

以下章节将介绍作为管理员需要执行的配置。

**Topics**
+ [让用户访问空间](studio-updated-jl-admin-guide-permissions.md)
+ [更改 JupyterLab 用户的默认存储大小](studio-updated-jl-admin-guide-storage-size.md)
+ [生命周期配置 JupyterLab](jl-lcc.md)
+ [Git 存储库在 JupyterLab](studio-updated-jl-admin-guide-git-attach.md)
+ [自定义镜像](studio-updated-jl-admin-guide-custom-images.md)
+ [更新 SageMaker 分发映像](studio-updated-jl-update-distribution-image.md)
+ [删除未使用的资源](studio-updated-jl-admin-guide-clean-up.md)
+ [配额](studio-updated-jl-admin-guide-quotas.md)

# 让用户访问空间
<a name="studio-updated-jl-admin-guide-permissions"></a>

要让用户访问专用空间或共享空间，您必须为其 IAM 角色附加权限策略。您还可以使用权限策略将专用空间及其相关应用程序限制为特定用户配置文件。

以下权限策略允许访问专用空间和共享空间。这样，用户就可以创建自己的空间，并列出其域内的其他空间。使用此策略的用户不能访问其他用户的专用空间。有关 Studio 空间的信息，请参阅 [亚马逊 SageMaker Studio 空间](studio-updated-spaces.md)。

该策略为用户提供以下权限：
+ 专用空间或共享空间。
+ 用于访问这些空间的用户配置文件。

要提供权限，您可以缩小以下策略的权限范围，并将其添加到用户的 IAM 角色中。您还可以使用此策略将您的空间及其相关应用程序限制为特定用户配置文件。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {

      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateApp",
        "sagemaker:DeleteApp"
      ],
      "Resource": "arn:aws:sagemaker:us-east-2:111122223333:app/*",
      "Condition": {
        "Null": {
          "sagemaker:OwnerUserProfileArn": "true"
        }
      }
    },
    {
      "Sid": "SMStudioCreatePresignedDomainUrlForUserProfile",
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreatePresignedDomainUrl"
      ],
      "Resource": "arn:aws:sagemaker:us-east-2:111122223333:user-profile/sagemaker:DomainId/sagemaker:UserProfileName"
    },
    {
      "Sid": "SMStudioAppPermissionsListAndDescribe",
      "Effect": "Allow",
      "Action": [
        "sagemaker:ListApps",
        "sagemaker:ListDomains",
        "sagemaker:ListUserProfiles",
        "sagemaker:ListSpaces",
        "sagemaker:DescribeApp",
        "sagemaker:DescribeDomain",
        "sagemaker:DescribeUserProfile",
        "sagemaker:DescribeSpace"
      ],
      "Resource": "*"
    },
    {
      "Sid": "SMStudioAppPermissionsTagOnCreate",
      "Effect": "Allow",
      "Action": [
        "sagemaker:AddTags"
      ],
      "Resource": "arn:aws:sagemaker:us-east-2:111122223333:*/*",
      "Condition": {
        "Null": {
          "sagemaker:TaggingAction": "false"
        }
      }
    },
    {
      "Sid": "SMStudioRestrictSharedSpacesWithoutOwners",
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateSpace",
        "sagemaker:UpdateSpace",
        "sagemaker:DeleteSpace"
      ],
      "Resource": "arn:aws:sagemaker:us-east-2:111122223333:space/sagemaker:DomainId/*",
      "Condition": {
        "Null": {
          "sagemaker:OwnerUserProfileArn": "true"
        }
      }
    },
    {
      "Sid": "SMStudioRestrictSpacesToOwnerUserProfile",
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateSpace",
        "sagemaker:UpdateSpace",
        "sagemaker:DeleteSpace"
      ],
      "Resource": "arn:aws:sagemaker:us-east-2:111122223333:space/sagemaker:DomainId/*",
      "Condition": {
        "ArnLike": {
        "sagemaker:OwnerUserProfileArn": "arn:aws:sagemaker:us-east-2:111122223333:user-profile/sagemaker:DomainId/sagemaker:UserProfileName"
        },
        "StringEquals": {
          "sagemaker:SpaceSharingType": [
            "Private",
            "Shared"
          ]
        }
      }
    },
    {
      "Sid": "SMStudioRestrictCreatePrivateSpaceAppsToOwnerUserProfile",
      "Effect": "Allow",
      "Action": [
        "sagemaker:CreateApp",
        "sagemaker:DeleteApp"
      ],
      "Resource": "arn:aws:sagemaker:us-east-2:111122223333:app/sagemaker:DomainId/*",
      "Condition": {
        "ArnLike": {
          "sagemaker:OwnerUserProfileArn": "arn:aws:sagemaker:us-east-2:111122223333:user-profile/sagemaker:DomainId/sagemaker:UserProfileName"
        },
        "StringEquals": {
          "sagemaker:SpaceSharingType": [
            "Private"
          ]
        }
      }
    }
  ]
}
```

------

# 更改 JupyterLab 用户的默认存储大小
<a name="studio-updated-jl-admin-guide-storage-size"></a>

您可以更改用户的默认存储空间设置。您还可以根据组织要求和用户需求更改默认存储设置。

要更改存储空间大小，本节提供了以下命令：

1. 更新亚马逊 A SageMaker I 域（域）中的亚马逊 EBS 存储设置。

1. 创建用户配置文件并在其中指定存储设置。

使用以下 AWS Command Line Interface (AWS CLI) 命令更改默认存储大小。

使用以下 AWS CLI 命令更新域：

```
aws --region AWS 区域 sagemaker update-domain \
--domain-id domain-id \
--default-user-settings '{
    "SpaceStorageSettings": {
        "DefaultEbsStorageSettings":{
            "DefaultEbsVolumeSizeInGb":5,
            "MaximumEbsVolumeSizeInGb":100
        }
    }
}'
```

使用以下 AWS CLI 命令创建用户配置文件并指定默认存储设置：

```
aws --region AWS 区域 sagemaker create-user-profile \
--domain-id domain-id \
--user-profile-name user-profile-name \
--user-settings '{
    "SpaceStorageSettings": {
        "DefaultEbsStorageSettings":{
            "DefaultEbsVolumeSizeInGb":5,
            "MaximumEbsVolumeSizeInGb":100
        }
    }
}'
```

使用以下 AWS CLI 命令更新用户配置文件中的默认存储设置：

```
aws --region AWS 区域 sagemaker update-user-profile \
--domain-id domain-id \
--user-profile-name user-profile-name \
--user-settings '{
    "SpaceStorageSettings": {
        "DefaultEbsStorageSettings":{
            "DefaultEbsVolumeSizeInGb":25,
            "MaximumEbsVolumeSizeInGb":200
        }
    }
}'
```

# 生命周期配置 JupyterLab
<a name="jl-lcc"></a>

生命周期配置是由生命 JupyterLab 周期事件（例如启动新 JupyterLab 笔记本）触发的 shell 脚本。您可以使用生命周期配置来自动为您的 JupyterLab 环境进行自定义。此自定义包括安装自定义软件包、配置笔记本扩展、预加载数据集以及设置源代码存储库。

使用生命周期配置使您可以灵活地进行配置 JupyterLab，从而满足您的特定需求。例如，您可以创建一套包含最常用软件包和库的最小基本容器映像。然后，您可以使用生命周期配置为数据科学和机器学习团队的特定使用场景安装其他软件包。

**注意**  
每个脚本的字符数上限为 **16384 个字符**。

**Topics**
+ [生命周期配置创建](jl-lcc-create.md)
+ [调试生命周期配置](jl-lcc-debug.md)
+ [分离生命周期配置](jl-lcc-delete.md)

# 生命周期配置创建
<a name="jl-lcc-create"></a>

本主题包括创建生命周期配置并将其与关联的说明。 JupyterLab您可以使用 AWS Command Line Interface (AWS CLI) 或自动 AWS 管理控制台 对您的 JupyterLab 环境进行自定义。

生命周期配置是由生命 JupyterLab 周期事件（例如启动新 JupyterLab 笔记本）触发的 shell 脚本。有关生命周期配置的更多信息，请参阅[生命周期配置 JupyterLab](jl-lcc.md)。

## 创建生命周期配置 (AWS CLI)
<a name="jl-lcc-create-cli"></a>

了解如何使用 AWS Command Line Interface (AWS CLI) 创建生命周期配置，自动为您的 Studio 环境进行自定义。

### 先决条件
<a name="jl-lcc-create-cli-prerequisites"></a>

在开始之前，请满足以下先决条件：
+  AWS CLI 按照[安装当前 AWS CLI 版本中的步骤进行](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html#install-tool-bundled)更新。
+ 在本地计算机上运行 `aws configure` 并提供您的 AWS 凭证。有关 AWS 证书的信息，请参阅[了解和获取您的 AWS 证书](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html)。
+ 登录 Amazon SageMaker AI 域名。有关概念性信息，请参阅 [亚马逊 SageMaker AI 域名概述](gs-studio-onboard.md)。有关快速入门指南，请参阅 [使用 Amazon A SageMaker I 的快速设置](onboard-quick-start.md)。

### 步骤 1：创建生命周期配置
<a name="jl-lcc-create-cli-step1"></a>

以下过程演示如何创建打印 `Hello World` 的生命周期配置脚本。

**注意**  
每个脚本最多可以包含 **16384 个字符**。

1. 在本地计算机上，创建一个名为 `my-script.sh` 的文件，内容如下：

   ```
   #!/bin/bash
   set -eux
   echo 'Hello World!'
   ```

1. 使用以下方法将 `my-script.sh` 文件转换为 base64 格式。此要求可防止因空格和换行编码而出现错误。

   ```
   LCC_CONTENT=`openssl base64 -A -in my-script.sh`
   ```

1. 创建用于 Studio 的生命周期配置。下面的命令创建一个生命周期配置，该配置在启动关联的 `JupyterLab` 应用程序时运行：

   ```
   aws sagemaker create-studio-lifecycle-config \
   --region region \
   --studio-lifecycle-config-name my-jl-lcc \
   --studio-lifecycle-config-content $LCC_CONTENT \
   --studio-lifecycle-config-app-type JupyterLab
   ```

   请记录为新创建的生命周期配置返回的 ARN。将生命周期配置附加到应用程序时需要此 ARN。

### 第 2 步：将生命周期配置附加到您的 Amazon SageMaker AI 域（域）和用户个人资料
<a name="jl-lcc-create-cli-step2"></a>

要附加生命周期配置，必须更新域的 `UserSettings` 或用户配置文件。在域级别关联的生命周期配置脚本由所有用户继承。但是，在用户配置文件级别关联的脚本的作用域限定为特定用户。

您可以使用以下命令创建附加生命周期配置的新用户配置文件、域或空间：
+ [create-user-profile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/create-user-profile.html)
+ [create-domain](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/create-domain.html)
+ [create-space](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/create-space.html)

下面的命令创建了一个具有生命周期配置的用户配置文件。将上一步中的生命周期配置 ARN 添加到用户的 `JupyterLabAppSettings` 中。您可以通过传递列表同时添加多个生命周期配置。当用户使用启动 JupyterLab 应用程序时 AWS CLI，他们可以指定生命周期配置，而不是使用默认配置。用户传递的生命周期配置必须属于 `JupyterLabAppSettings` 中的生命周期配置列表。

```
# Create a new UserProfile
aws sagemaker create-user-profile --domain-id domain-id \
--user-profile-name user-profile-name \
--region region \
--user-settings '{
"JupyterLabAppSettings": {
  "LifecycleConfigArns":
    [lifecycle-configuration-arn-list]
  }
}'
```

## 创建生命周期配置（管理控制台）
<a name="jl-lcc-create-console"></a>

了解如何使用创建生命周期配置，自动为您的 AWS 管理控制台 Studio 环境进行自定义。

### 步骤 1：创建生命周期配置
<a name="jl-lcc-create-console-step1"></a>

使用以下过程创建打印 `Hello World` 的生命周期配置脚本。

**创建生命周期配置**

1. 打开 Amazon A SageMaker I 控制台，网址为[https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/)。

1. 在左侧导航窗格中，选择**管理员配置**。

1. 在**管理员配置**下，选择**生命周期配置**。

1. 选择 **JupyterLab** 选项卡。

1. 选择**创建配置**。

1. 在**名称**中，指定生命周期配置的名称。

1. 在**脚本**下的文本框中，指定以下生命周期配置：

   ```
   #!/bin/bash
   set -eux
   echo 'Hello World!'
   ```

1. 选择**创建配置**。

### 第 2 步：将生命周期配置附加到您的 Amazon SageMaker AI 域（域）和用户个人资料
<a name="jl-lcc-create-console-step2"></a>

在域级别关联的生命周期配置脚本由所有用户继承。但是，在用户配置文件级别关联的脚本的作用域限定为特定用户。

您可以将多个生命周期配置附加到域名或用户配置文件中 JupyterLab。

使用以下步骤将生命周期配置附加到域。

**将生命周期配置附加到域**

1. 打开 Amazon A SageMaker I 控制台，网址为[https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/)。

1. 在左侧导航窗格中，选择**管理员配置**。

1. 在**管理员配置**下，选择**域**。

1. 从域列表中，选择要将生命周期配置附加到的域。

1. 在**域详细信息**页面上，选择**环境**选项卡。

1. 在**个人 Studio 应用程序的生命周期配置**下，选择**附加**。

1. 在**来源**下，选择**现有配置**。

1. 在 **Studio 生命周期配置**下，选择在上一步中创建的生命周期配置。

1. 选择**附加到域**。

使用以下步骤将生命周期配置附加到用户配置文件。

**将生命周期配置附加到用户配置文件**

1. 打开 Amazon A SageMaker I 控制台，网址为[https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/)。

1. 在左侧导航窗格中，选择**管理员配置**。

1. 在**管理员配置**下，选择**域**。

1. 从域列表中，选择包含要附加生命周期配置的用户配置文件的域。

1. 在**用户配置文件**下，选择用户配置文件。

1. 在**用户详细信息**页面上，选择**编辑**。

1. 在左侧导航中，选择 **Studio 设置**。

1. 在**附加到用户的生命周期配置**下，选择**附加**。

1. 在**来源**下，选择**现有配置**。

1. 在 **Studio 生命周期配置**下，选择在上一步中创建的生命周期配置。

1. 选择**附加到用户配置文件**。

# 调试生命周期配置
<a name="jl-lcc-debug"></a>

以下主题介绍了如何获取生命周期配置的相关信息并进行调试。

**Topics**
+ [从 L CloudWatch ogs 中验证生命周期配置流程](#jl-lcc-debug-logs)
+ [生命周期配置超时](#jl-lcc-debug-timeout)

## 从 L CloudWatch ogs 中验证生命周期配置流程
<a name="jl-lcc-debug-logs"></a>

生命周期配置仅记录 `STDOUT` 和 `STDERR`。

`STDOUT` 是 bash 脚本的默认输出。您可以通过在 bash 命令的末尾追加 `>&2` 来写入 `STDERR`。例如 `echo 'hello'>&2`。

您的生命周期配置日志将 AWS 账户 使用 Amazon 发布给您 CloudWatch。这些日志可以在 CloudWatch 控制台的`/aws/sagemaker/studio`日志流中找到。

1. 打开 CloudWatch 控制台，网址为[https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/)。

1. 从左侧导航窗格中选择**日志**。从下拉菜单中，选择**日志组**。

1. 在**日志组**页面上，搜索 `aws/sagemaker/studio`。

1. 选择日志组。

1. 在**日志组详细信息**页面上，选择**日志流**选项卡。

1. 要查找特定空间的日志，请使用以下格式搜索日志流：

   ```
   domain-id/space-name/app-type/default/LifecycleConfigOnStart
   ```

   例如，要查找域 ID `d-m85lcu8vbqmz`、空间名称 `i-sonic-js` 和应用程序类型 `JupyterLab` 的生命周期配置日志，请使用以下搜索字符串：

   ```
   d-m85lcu8vbqmz/i-sonic-js/JupyterLab/default/LifecycleConfigOnStart
   ```

## 生命周期配置超时
<a name="jl-lcc-debug-timeout"></a>

生命周期配置超时限制为 5 分钟。如果生命周期配置脚本的运行时间超过 5 分钟，就会出现错误。

要解决此错误，请确保生命周期配置脚本在 5 分钟内完成。

为了缩短脚本的运行时间，请尝试以下方法：
+ 减少不必要的步骤。例如，限制在哪些 conda 环境中安装大型软件包。
+ 在并行进程中运行任务。
+ 在脚本中使用 nohup 命令可确保忽略挂起信号，从而使脚本不会停止运行。

# 分离生命周期配置
<a name="jl-lcc-delete"></a>

要更新您的脚本，您必须创建一个新的生命周期配置脚本并将其附加到相应的 Amazon SageMaker AI 域（域）、用户资料或共享空间。生命周期配置脚本创建后不能更改。有关创建和附加生命周期配置的更多信息，请参阅 [生命周期配置创建](jl-lcc-create.md)。

以下章节演示如何使用 AWS Command Line Interface (AWS CLI) 分离生命周期配置。

## 使用 “分离” AWS CLI
<a name="jl-lcc-delete-cli"></a>

要使用 (AWS CLI) 分离生命周期配置，请从附加到资源的生命周期配置列表中删除所需的生命周期配置。然后您将此列表作为相应命令的一部分传递：
+ [update-user-profile](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/update-user-profile.html)
+ [update-domain](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/update-domain.html)
+ [update-space](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/update-space.html)

例如，以下命令删除附加到该域的 JupyterLab 应用程序的所有生命周期配置。

```
aws sagemaker update-domain --domain-id domain-id \
--region region \
--default-user-settings '{
"JupyterLabAppSettings": {
  "LifecycleConfigArns":
    []
  }
}'
```

# Git 存储库在 JupyterLab
<a name="studio-updated-jl-admin-guide-git-attach"></a>

JupyterLab 提供了 Git 扩展，用于输入 Git 存储库 (repo) 的 URL、将其克隆到环境中、推送更改以及查看提交历史记录。您也可以将建议的 Git 存储库附加 URLs 到 Amazon SageMaker AI 域（域）或用户个人资料。

以下各节介绍如何附加或分离 Git 存储库 URLs。

**Topics**
+ [附加 Git 存储库 (AWS CLI)](studio-updated-git-attach-cli.md)
+ [分离 Git 存储库 URLs](studio-updated-git-detach.md)

# 附加 Git 存储库 (AWS CLI)
<a name="studio-updated-git-attach-cli"></a>

本节介绍如何使用附加 Git 存储库 (repo) 网址。 AWS CLI附加 Git 存储库 URL 后，您可以按照 [在亚马逊 SageMaker Studio 中克隆 Git 存储库](#studio-updated-tasks-git) 中的步骤对其进行克隆。

## 先决条件
<a name="studio-updated-git-attach-cli-prerequisites"></a>

在开始之前，请满足以下先决条件：
+  AWS CLI 按照[安装当前 AWS Command Line Interface 版本中的步骤进行](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html#install-tool-bundled)更新。
+ 在本地计算机上运行 `aws configure` 并提供您的 AWS 凭证。有关 AWS 证书的信息，请参阅[了解和获取您的 AWS 证书](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html)。
+ 登录 Amazon SageMaker AI 域名。有关更多信息，请参阅 [亚马逊 SageMaker AI 域名概述](gs-studio-onboard.md)。

## 将 Git 存储库附加到亚马逊 A SageMaker I 域（域）或用户个人资料
<a name="studio-updated-git-attach-cli-attach"></a>

在域级别关联 URLs 的 Git 存储库由所有用户继承。但是，在用户配置文件级别关联 URLs 的 Git 存储库仅限于特定用户。您可以通过传递存储库 URLs 列表将多个 Git 存储库 URLs附加到一个 SageMaker Amazon AI 域或用户个人资料。

下面几节介绍如何将 Git 存储库 URL 附加到域和用户配置文件。

### 附加到亚马逊 A SageMaker I 域名
<a name="studio-updated-git-attach-cli-attach-domain"></a>

以下命令将 Git 存储库 URL 附加到现有域：

```
aws sagemaker update-domain --region region --domain-id domain-id \
    --default-user-settings JupyterLabAppSettings={CodeRepositories=[{RepositoryUrl="repository"}]}
```

### 附加到用户配置文件
<a name="studio-updated-git-attach-cli-attach-userprofile"></a>

以下命令会将 Git 存储库 URL 附加到现有的用户配置文件：

```
aws sagemaker update-user-profile --domain-id domain-id --user-profile-name user-name\
    --user-settings JupyterLabAppSettings={CodeRepositories=[{RepositoryUrl="repository"}]}
```

## 在亚马逊 SageMaker Studio 中克隆 Git 存储库
<a name="studio-updated-tasks-git"></a>

Amazon SageMaker Studio 仅连接到本地 Git 存储库。要访问存储库中的文件，请在 Studio 中克隆 Git 存储库。为此，Studio 提供了 Git 扩展，供您输入 Git 存储库的 URL、将其克隆到您的环境中、推送更改以及查看提交历史记录。

如果存储库是专用的，需要凭证才能访问，则会收到输入用户凭证的提示。您的凭证包括用户名和专用访问令牌。有关个人访问令牌的更多信息，请参阅[管理个人访问令牌](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)。

管理员还可以在 Amazon A SageMaker I 域或用户个人资料级别附加建议的 Git 存储库 URLs 。然后，用户可以从建议列表中选择存储库 URL，并将其克隆到 Studio 中。有关附加建议的存储库的更多信息，请参阅 [将建议的 Git 存储库附加到亚马逊 SageMaker Studio Classic](studio-git-attach.md)。

# 分离 Git 存储库 URLs
<a name="studio-updated-git-detach"></a>

本节介绍如何将 Git 存储库 URLs 与 Amazon A SageMaker I 域（域）或用户个人资料分离。您可以使用 AWS Command Line Interface (AWS CLI) 或 Amazon A SageMaker I 控制台分离存储库 URLs 。

## 使用分离 Git 存储库 AWS CLI
<a name="studio-updated-git-detach-cli"></a>

要将所有 Git 存储库 URLs 与域名或用户配置文件分离，必须传递一个空的代码存储库列表。此列表作为 `update-domain` 或 `update-user-profile` 命令中 `JupyterLabAppSettings` 参数的一部分传递。要仅分离一个 Git 存储库 URL，请传递不包含所需的 Git 存储库 URL 的代码存储库列表。

### 与亚马逊 A SageMaker I 域名分离
<a name="studio-updated-git-detach-cli-domain"></a>

以下命令将所有 Git 存储库 URLs 从域中分离出来：

```
aws sagemaker update-domain --region region --domain-name domain-name \
    --domain-settings JupyterLabAppSettings={CodeRepositories=[]}
```

### 从用户配置文件中分离
<a name="studio-updated-git-detach-cli-userprofile"></a>

以下命令将所有 Git 存储库 URLs 从用户配置文件中分离出来：

```
aws sagemaker update-user-profile --domain-name domain-name --user-profile-name user-name\
    --user-settings JupyterLabAppSettings={CodeRepositories=[]}
```

# 自定义镜像
<a name="studio-updated-jl-admin-guide-custom-images"></a>

如果您需要的功能与 SageMaker 发行版提供的功能不同，则可以自带带有自定义扩展和软件包的镜像。您还可以使用它对 JupyterLab 用户界面进行个性化设置，以满足自己的品牌或合规需求。

下一页将提供 JupyterLab特定信息和模板，用于创建您自己的自定义 SageMaker AI 镜像。这旨在补充 Amazon SageMaker Studio 关于创建自己的 SageMaker AI 图像和将自己的图像带到 Studio 的信息和说明。要了解有关自定义 Amazon SageMaker AI 图像以及如何将自己的图像带到 Studio 的信息，请参阅[自带映像（BYOI）](studio-updated-byoi.md)。

**Topics**
+ [应用程序的运行状况检查和 URL](#studio-updated-jl-admin-guide-custom-images-app-healthcheck)
+ [Dockerfile 示例](#studio-updated-jl-custom-images-dockerfile-templates)

## 应用程序的运行状况检查和 URL
<a name="studio-updated-jl-admin-guide-custom-images-app-healthcheck"></a>
+ `Base URL`：BYOI 应用程序的基本 URL 必须为 `jupyterlab/default`。您只能有一个应用程序，且必须始终命名为 `default`。
+ `HealthCheck API`— SageMaker AI 使用端口的运行状况检查端点`8888`来检查 JupyterLab应用程序的运行状况。 `jupyterlab/default/api/status`是运行状况检查的终端节点。
+ `Home/Default URL`— 使用的`/opt/.sagemakerinternal`和`/opt/ml`目录 AWS。`/opt/ml` 中的元数据文件包含有关 `DomainId` 等资源的元数据。
+ 身份验证：要为用户启用身份验证，请关闭基于令牌或密码的 Jupyter Notebook 身份验证，并允许所有来源。

## Dockerfile 示例
<a name="studio-updated-jl-custom-images-dockerfile-templates"></a>

以下示例是符合上述信息与[自定义映像规范](studio-updated-byoi-specs.md)的 `Dockerfile`。

**注意**  
如果您要将自己的镜像带到 SageMaker Unified Studio，则需要遵循*亚马逊 Unifie SageMaker d Studio 用户*[指南中的 Dockerfile 规范](https://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/byoi-specifications.html)。  
`Dockerfile` SageMaker Unified Studio 的示例可以在*亚马逊 Unified Studio 用户指南的 Docker SageMaker f* [ile 示例](https://docs.aws.amazon.com/sagemaker-unified-studio/latest/userguide/byoi-specifications.html#byoi-specifications-example)中找到。

------
#### [ Example AL2023 Dockerfile ]

以下是符合上述信息与[自定义映像规范](studio-updated-byoi-specs.md)的示例 AL2023 Dockerfile。

```
FROM public.ecr.aws/amazonlinux/amazonlinux:2023

ARG NB_USER="sagemaker-user"
ARG NB_UID=1000
ARG NB_GID=100

# Install Python3, pip, and other dependencies
RUN yum install -y \
    python3 \
    python3-pip \
    python3-devel \
    gcc \
    shadow-utils && \
    useradd --create-home --shell /bin/bash --gid "${NB_GID}" --uid ${NB_UID} ${NB_USER} && \
    yum clean all

RUN python3 -m pip install --no-cache-dir \
    'jupyterlab>=4.0.0,<5.0.0' \
    urllib3 \
    jupyter-activity-monitor-extension \
    --ignore-installed

# Verify versions
RUN python3 --version && \
    jupyter lab --version

USER ${NB_UID}
CMD jupyter lab --ip 0.0.0.0 --port 8888 \
    --ServerApp.base_url="/jupyterlab/default" \
    --ServerApp.token='' \
    --ServerApp.allow_origin='*'
```

------
#### [ Example 亚马逊 SageMaker 配送 Dockerfile ]

以下是符合上述信息与[自定义映像规范](studio-updated-byoi-specs.md)的示例 Amazon SageMaker Distribution Dockerfile。

```
FROM public.ecr.aws/sagemaker/sagemaker-distribution:latest-cpu
ARG NB_USER="sagemaker-user"
ARG NB_UID=1000
ARG NB_GID=100

ENV MAMBA_USER=$NB_USER

USER root

RUN apt-get update
RUN micromamba install sagemaker-inference --freeze-installed --yes --channel conda-forge --name base

USER $MAMBA_USER

ENTRYPOINT ["entrypoint-jupyter-server"]
```

------

# 更新 SageMaker 分发映像
<a name="studio-updated-jl-update-distribution-image"></a>

**重要**  
本主题假设您已经创建了空间，并赋予了用户访问该空间的权限。有关更多信息，请参阅 [让用户访问空间](studio-updated-jl-admin-guide-permissions.md)。

更新您已经创建的 JupyterLab 空间，以使用最新版本的 SageMaker 分发映像来访问最新功能。您可以使用 Studio 用户界面或 AWS Command Line Interface (AWS CLI) 来更新图像。

以下章节提供了有关更新映像的信息。

## 更新映像（用户界面）
<a name="studio-updated-jl-update-distribution-image-ui"></a>

更新图像涉及重新启动用户 JupyterLab 空间。使用以下步骤使用最新图像更新用户 JupyterLab 空间。

**更新映像（用户界面）**

1. 打开 Studio。有关打开 Studio 的信息，请参阅 [启动亚马逊 SageMaker Studio](studio-updated-launch.md)。

1. 选择 **JupyterLab**。

1. 选择您的用户 JupyterLab 空间。

1. 选择**停止空间**。

1. 在 “**图像**” 中，选择 A SageMaker I 分发映像的更新版本。要获取最新映像，请选择 **最新**。

1. 选择**运行空间**。

## 更新映像 (AWS CLI)
<a name="studio-updated-jl-update-distribution-image-cli"></a>

本节假设您已安装了 AWS Command Line Interface (AWS CLI)。有关安装的信息 AWS CLI，请参阅[安装或更新到最新版本的 AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

要更新映像，您必须为用户空间执行以下操作：

1. 删除 JupyterLab 应用程序

1. 更新空间

1. 创建应用程序

**重要**  
在开始更新映像之前，您必须准备好以下信息：  
域 ID — 您的用户的 Amazon A SageMaker I 域名的 ID。
应用程序类型 — JupyterLab.
应用程序名称：默认。
空间名称：为空间指定的名称。
实例类型：用于运行应用程序的 Amazon EC2 实例类型。例如 `ml.t3.medium`。
SageMaker 图片 ARN — AI 分发映像的亚马逊资源名称 (ARN)。 SageMaker 您可以通过将`sagemaker-distribution-cpu`或`sagemaker-distribution-gpu`指定为资源标识符来提供最新版本的 SageMaker AI 分布映像。

要删除 JupyterLab 应用程序，请运行以下命令：

```
aws sagemaker delete-app \
--domain-id your-user's-domain-id 
--app-type JupyterLab \
--app-name default \
--space-name name-of-your-user's-space
```

要更新用户空间，请运行以下命令：

```
aws sagemaker update-space \
--space-name name-of-your-user's-space \
--domain-id your-user's-domain-id
```

如果您成功更新了空间，就会在响应中看到空间 ARN：

```
{
"SpaceArn": "arn:aws:sagemaker:AWS 区域:111122223333:space/your-user's-domain-id/name-of-your-user's-space"
}
```

要创建应用程序，请运行以下命令：

```
aws sagemaker create-app \
--domain-id your-user's-domain-id  \
--app-type JupyterLab \
--app-name default \
--space-name name-of-your-user's-space \
--resource-spec "InstanceType=instance-type,SageMakerImageArn=arn:aws:sagemaker:AWS 区域:555555555555:image/sagemaker-distribution-resource-identifier"
```

# 删除未使用的资源
<a name="studio-updated-jl-admin-guide-clean-up"></a>

为避免产生额外的运行成本 JupyterLab，我们建议按以下顺序删除未使用的资源：

1. JupyterLab 应用程序

1. 空间

1. 用户配置文件

1. 域

使用以下 AWS Command Line Interface (AWS CLI) 命令删除域内的资源：

------
#### [ Delete a JupyterLab application ]

```
aws --region AWS 区域 sagemaker delete-app --domain-id example-domain-id --app-name default --app-type JupyterLab --space-name example-space-name
```

------
#### [ Delete a space ]

**重要**  
如果您删除一个空间，就会删除与其相关的 Amazon EBS 卷。我们建议您在删除空间前备份任何有价值的数据。

```
aws --region AWS 区域 sagemaker delete-space --domain-id example-domain-id  --space-name example-space-name
```

------
#### [ Delete a user profile ]

```
aws --region AWS 区域 sagemaker delete-user-profile --domain-id example-domain-id --user-profile example-user-profile
```

------

# 配额
<a name="studio-updated-jl-admin-guide-quotas"></a>

JupyterLab，有以下配额：
+  AWS 账户内所有 Amazon EBS 卷的总和。
+ 用户可用的实例类型。
+ 用户可以启动的特定实例数量。

要为用户获取更多存储和计算资源，请求增加 AWS 配额。有关申请增加配额的更多信息，请参阅 [Amazon A SageMaker I 终端节点和配额](https://docs.aws.amazon.com/general/latest/gr/sagemaker.html)。