

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

# 设置空闲关闭
<a name="studio-updated-idle-shutdown-setup"></a>

 下文将介绍如何通过管理控制台或使用 AWS CLI设置空闲关闭。空闲关闭可在域或用户配置文件级别设置。

## 先决条件
<a name="studio-updated-idle-shutdown-setup-prereq"></a>

 要在应用程序中使用空闲关闭功能，您必须满足以下先决条件。
+ 确保您的应用程序使用的是 SageMaker 发行版 (SMD) 2.0。您可以在创建应用程序时选择该版本，也可以在创建后更新应用程序的映像版本。有关更多信息，请参阅 [更新 SageMaker 分发映像](studio-updated-jl-update-distribution-image.md)。
+ 对于使用自定义映像构建的应用程序，如果您的自定义映像是使用 SageMaker 发行版 (SMD) 2.0 或更高版本作为基础映像创建的，则支持空闲关机。如果使用不同的基础映像创建自定义映像，则必须在图像上安装 [jupyter-activity-monitor-extension >= 0.3.1](https://anaconda.org/conda-forge/jupyter-activity-monitor-extension) 扩展插件，并将该图像附加到您的 Amazon A SageMaker I 域以供 JupyterLab 应用程序使用。有关自定义映像的更多信息，请参阅[自带映像（BYOI）](studio-updated-byoi.md)。

## 通过控制台
<a name="studio-updated-idle-shutdown-setup-console"></a>

 以下章节将介绍如何从管理控制台启用空闲关闭。

### 创建新域时添加
<a name="studio-updated-idle-shutdown-setup-console-new-domain"></a>

1. 按照 [使用 Amazon A SageMaker I 的自定义设置](onboard-custom.md) 中的步骤创建域 

1.  在域中配置应用程序设置时，请导航到代码编辑器或 JupyterLab 部分。  

1.  选择**启用空闲关闭**。

1.  输入默认空闲关闭时间（分钟）。如果没有输入值，则默认为 `10,080`。

1.  (可选）选择**允许用户设置自定义空闲关闭时间**，允许用户修改空闲关闭时间。
   +  输入用户可设置默认空闲关闭时间的最大值。您必须输入最大值。最小值由 Amazon A SageMaker I 设定，必须为`60`。

### 添加到现有域
<a name="studio-updated-idle-shutdown-setup-console-existing-domain"></a>

**注意**  
如果在应用程序运行时设置了空闲关闭，则必须重新启动应用程序才能使空闲关闭设置生效。

1.  导航到域。

1.  选择**应用程序配置**选项卡。

1.  在 “**应用程序配置**” 选项卡中，导航到 “代码编辑器” 或 “ JupyterLab 部分”。

1.  选择**编辑**。

1.  选择**启用空闲关闭**。

1.  输入默认空闲关闭时间（分钟）。如果没有输入值，则默认为 `10,080`。

1.  (可选）选择**允许用户设置自定义空闲关闭时间**，允许用户修改空闲关闭时间。
   +  输入用户可设置默认空闲关闭时间的最大值。必须输入最大值。 最小值由 Amazon A SageMaker I 设定，必须为`60`。

1.  选择**提交**。

### 在创建新用户配置文件时添加
<a name="studio-updated-idle-shutdown-setup-console-new-userprofile"></a>

1. 按照 [添加用户配置文件](domain-user-profile-add.md) 中的步骤添加用户配置文件 

1.  为用户配置文件配置应用程序设置时，请导航到代码编辑器或 JupyterLab 部分。

1.  选择**启用空闲关闭**。

1.  输入默认空闲关闭时间（分钟）。如果没有输入值，则默认为 `10,080`。

1.  (可选）选择**允许用户设置自定义空闲关闭时间**，允许用户修改空闲关闭时间。
   +  输入用户可设置默认空闲关闭时间的最大值。必须输入最大值。 最小值由 Amazon A SageMaker I 设定，必须为`60`。

1.  选择“保存更改”。

### 添加到现有用户配置文件
<a name="studio-updated-idle-shutdown-setup-console-existing-userprofile"></a>

 注意：如果在应用程序运行时设置了空闲关闭，则必须重新启动应用程序才能使空闲关闭设置生效。

1.  导航至用户配置文件。

1.  选择**应用程序配置**选项卡。

1.  在 “****应用程序配置****” 选项卡中，导航到 “代码编辑器” 或 “ JupyterLab 部分”。  

1.  选择**编辑**。

1.  如果为域配置了空闲关闭设置，则默认情况下会显示域设置。

1.  选择**启用空闲关闭**。

1.  输入默认空闲关闭时间（分钟）。如果没有输入值，则默认为 `10,080`。

1.  (可选）选择**允许用户设置自定义空闲关闭时间**，允许用户修改空闲关闭时间。
   +  输入用户可设置默认空闲关闭时间的最大值。必须输入最大值。 最小值由 Amazon A SageMaker I 设定，必须为`60`。

1.  选择**保存更改**。

## 来自 AWS CLI
<a name="studio-updated-idle-shutdown-setup-cli"></a>

 下文将介绍如何使用 AWS CLI启用空闲关闭。

**注意**  
要强制使用中的特定超时值 AWS CLI，必须将`IdleTimeoutInMinutes``MaxIdleTimeoutInMinutes`、和设置`MinIdleTimeoutInMinutes`为相同的值。

### 域：
<a name="studio-updated-idle-shutdown-setup-cli-domain"></a>

 以下命令显示了如何在更新现有域时启用空闲关闭。要为新域添加空闲关闭，请使用 `create-domain` 命令。

**注意**  
如果在应用程序运行时设置了空闲关闭，则必须重新启动应用程序才能使空闲关闭设置生效。

```
aws sagemaker update-domain --region region --domain-id domain-id \
--default-user-settings file://default-user-settings.json

## default-user-settings.json example for enforcing the default timeout
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120
        }
    }
}

## default-user-settings.json example for letting users customize the default timeout, between 2-5 hours
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 300
        }
    }
}
```

### 用户配置文件
<a name="studio-updated-idle-shutdown-setup-cli-userprofile"></a>

 以下命令显示了如何在更新现有用户配置文件时启用空闲关闭。要为新用户配置文件添加空闲关闭，请使用 `create-user-profile` 命令。

**注意**  
如果在应用程序运行时设置了空闲关闭，则必须重新启动应用程序才能使空闲关闭设置生效。

```
aws sagemaker update-user-profile --region region --domain-id domain-id \
--user-profile-name user-profile-name --user-settings file://user-settings.json

## user-settings.json example for enforcing the default timeout
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120
        }
    }
}

## user-settings.json example for letting users customize the default timeout, between 2-5 hours
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 300
        }
    }
}
```