

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

# 为 Amazon SageMaker Studio AWS CLI Classic 设置默认值
<a name="studio-lcc-defaults-cli"></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 资源的权限已经包括在创建这些资源时添加标签的权限。

**重要**  
截至 2023 年 11 月 30 日，之前的亚马逊 SageMaker Studio 体验现在被命名为 Amazon St SageMaker udio Classic。以下部分专门介绍如何使用 Studio Classic 应用程序。有关使用更新的 Studio 体验的信息，请参阅 [亚马逊 SageMaker Studio](studio-updated.md)。  
Studio Classic 仍针对现有工作负载进行维护，但不再可供入门使用。您只能停止或删除现有的 Studio Classic 应用程序，不能创建新的应用程序。我们建议您将[工作负载迁移到全新 Studio 体验](studio-updated-migrate.md)。

您可以从中 AWS CLI 为以下资源设置默认生命周期配置脚本：
+ Domains
+ 用户配置文件
+ 共享空间

下面几节概述了如何从 AWS CLI设置默认生命周期配置脚本。

**Topics**
+ [先决条件](#studio-lcc-defaults-cli-prereq)
+ [创建新资源时设置默认生命周期配置](#studio-lcc-defaults-cli-new)
+ [为现有资源设置默认生命周期配置](#studio-lcc-defaults-cli-existing)

## 先决条件
<a name="studio-lcc-defaults-cli-prereq"></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)。
+ 按照中的步骤登录 SageMaker AI 域[亚马逊 SageMaker AI 域名概述](gs-studio-onboard.md)。
+ 按照 [创建生命周期配置并将其与 Amazon SageMaker Studio Classic 关联](studio-lcc-create.md) 中的步骤创建生命周期配置。

## 创建新资源时设置默认生命周期配置
<a name="studio-lcc-defaults-cli-new"></a>

要在创建新域、用户配置文件或空间时设置默认生命周期配置，请将之前创建的生命周期配置的 ARN 作为以下 AWS CLI 命令之一的一部分传递：
+ [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/opensearch/create-domain.html)
+ [create-space](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sagemaker/create-space.html)

您必须为 KernelGateway 或 JupyterServer 默认设置中的以下值传递生命周期配置 ARN：
+ `DefaultResourceSpec`:`LifecycleConfigArn` - 这指定应用程序类型的默认生命周期配置。
+ `LifecycleConfigArns` - 这是附加到应用程序类型的所有生命周期配置的列表。默认生命周期配置也必须包含在此列表中。

例如，以下 API 调用使用默认生命周期配置创建一个新的用户配置文件。

```
aws sagemaker create-user-profile --domain-id {{domain-id}} \
--user-profile-name {{user-profile-name}} \
--region {{region}} \
--user-settings '{
"KernelGatewayAppSettings": {
    "DefaultResourceSpec": { 
            "InstanceType": "ml.t3.medium",
            "LifecycleConfigArn": "{{lifecycle-configuration-arn}}"
         },
    "LifecycleConfigArns": [{{lifecycle-configuration-arn-list}}]
  }
}'
```

## 为现有资源设置默认生命周期配置
<a name="studio-lcc-defaults-cli-existing"></a>

要设置或更新现有资源的默认生命周期配置，请将之前创建的生命周期配置的 ARN 作为以下 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)

您必须为 KernelGateway 或 JupyterServer 默认设置中的以下值传递生命周期配置 ARN：
+ `DefaultResourceSpec`:`LifecycleConfigArn` - 这指定应用程序类型的默认生命周期配置。
+ `LifecycleConfigArns` - 这是附加到应用程序类型的所有生命周期配置的列表。默认生命周期配置也必须包含在此列表中。

例如，以下 API 调用使用默认生命周期配置更新用户配置文件。

```
aws sagemaker update-user-profile --domain-id {{domain-id}} \
--user-profile-name {{user-profile-name}} \
--region {{region}} \
--user-settings '{
"KernelGatewayAppSettings": {
    "DefaultResourceSpec": {
            "InstanceType": "ml.t3.medium",
            "LifecycleConfigArn": "{{lifecycle-configuration-arn}}"
         },
    "LifecycleConfigArns": [{{lifecycle-configuration-arn-list}}]
  }
}'
```

以下 API 调用可更新域以设置新的默认生命周期配置。

```
aws sagemaker update-domain --domain-id {{domain-id}} \
--region {{region}} \
--default-user-settings '{
"JupyterServerAppSettings": {
    "DefaultResourceSpec": {
            "InstanceType": "system",
            "LifecycleConfigArn": "{{lifecycle-configuration-arn}}"
         },
    "LifecycleConfigArns": [{{lifecycle-configuration-arn-list}}]
  }
}'
```