

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

# 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)。