

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

# 清理映像资源
<a name="rstudio-byoi-sdk-cleanup"></a>

本指南介绍如何清理您在前几节中创建的 RStudio 图像资源。要删除图像，请使用 SageMaker AI 控制台或本指南中所示完成以下步骤。 Amazon CLI
+ 将图像和图像版本与您的 Amazon A SageMaker I 域分离。
+ 删除映像、映像版本和应用程序映像配置。

完成这些步骤后，您可以从 Amazon ECR 中删除容器映像和存储库。有关如何删除容器映像和存储库的更多信息，请参阅[删除存储库](https://docs.amazonaws.cn/AmazonECR/latest/userguide/repository-delete.html)。

## 从 SageMaker AI 控制台清理资源
<a name="rstudio-byoi-sdk-cleanup-console"></a>

从域中分离映像时，将分离该映像的所有版本。分离映像后，域的所有用户都将失去对映像版本的访问权限。

**分离映像**

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

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

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

1. 选择所需的域。

1. 选择**环境**。

1. 在**附加到域的自定义映像**下，选择映像，然后选择**分离**。

1. （可选）要从 SageMaker AI 中删除图像和所有版本，请选择**同时删除所选图像...** 。这不会从 Amazon ECR 中删除关联的映像。

1. 选择**分离**。

## 清理来自的资源 Amazon CLI
<a name="rstudio-byoi-sdk-cleanup-cli"></a>

**清理资源**

1. 通过向域传递一个空的自定义映像列表，将映像和映像版本从域中分离。打开在 [将 SageMaker 图片附加到您当前的域名](studio-byoi-attach.md#studio-byoi-sdk-attach-current-domain) 中创建的 `update-domain-input.json` 文件。

1. 删除 `RSessionAppSettings` 自定义映像，然后保存文件。请勿修改 `KernelGatewayAppSettings` 自定义映像。

   ```
   {
       "DomainId": "d-xxxxxxxxxxxx",
       "DefaultUserSettings": {
         "KernelGatewayAppSettings": {
            "CustomImages": [
            ],
            ...
         },
         "RSessionAppSettings": { 
           "CustomImages": [ 
           ],
           "DefaultResourceSpec": { 
           }
           ...
         }
       }
   }
   ```

1. 使用域 ID 和默认用户设置文件更新域。

   ```
   aws sagemaker update-domain \
       --domain-id <d-xxxxxxxxxxxx> \
       --cli-input-json file://update-domain-input.json
   ```

   响应：

   ```
   {
       "DomainArn": "arn:aws:sagemaker:us-east-2:acct-id:domain/d-xxxxxxxxxxxx"
   }
   ```

1. 删除应用程序映像配置。

   ```
   aws sagemaker delete-app-image-config \
       --app-image-config-name rstudio-image-config
   ```

1. 删除 SageMaker 图像，这也会删除所有图像版本。Amazon ECR 中由映像版本表示的容器映像不会被删除。

   ```
   aws sagemaker delete-image \
       --image-name rstudio-image
   ```