

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

# 配置 RES-ready AMIs
<a name="res-ready-ami"></a>

借助可重置的 Amazon 系统映像 (AMI)，您可以在自定义 AMI 上预安装虚拟桌面实例 (VDI) 的 RES 依赖项。使用 RES-ready AMI 可以缩短使用预烘焙映像的 VDI 实例的启动时间。使用 EC2 Image Builder，您可以构建自己的软件堆栈并将其注册 AMIs 为新的软件堆栈。有关 Image Builder 的更多信息，请参阅 [Image Builder 用户指南](https://docs.aws.amazon.com/imagebuilder/latest/userguide/what-is-image-builder.html)。

在开始之前，必须[部署最新版本的 RES](update-the-product.md)。

**重要**  
在 RES 2025.06.01 之前 AMIs 创建的 Res-ready 与 RES 2025.06.01 和所有后续版本不兼容。将 RES 环境从 2025.06.01 之前的版本升级到最新版本时，必须重建所有 RES就绪。 AMIs

**Topics**
+ [准备一个 IAM 角色以访问 RES 环境](#prepare-role)
+ [创建 EC2 Image Builder 组件](#image-builder-component)
+ [准备好您的 EC2 Image Builder 配方](#prepare-recipe)
+ [配置 EC2 Image Builder 基础架构](#configure-ib-infrastructure)
+ [配置 Image Builder 图像管道](#image-builder-pipeline)
+ [运行 Image Builder 图像管道](#run-image-pipeline)
+ [在 RES 中注册新的软件堆栈](#register-res-ready-stack)

## 准备一个 IAM 角色以访问 RES 环境
<a name="prepare-role"></a>

要从 EC2 Image Builder 访问 RES 环境服务，您必须创建或修改名为 RES-的 IAM 角色EC2InstanceProfileForImageBuilder。有关配置在 Image Builder 中使用的 IAM 角色的信息，请参阅 Imag *e Builder 用户指南*[中的AWS Identity and Access Management (IAM)](https://docs.aws.amazon.com/imagebuilder/latest/userguide/image-builder-setting-up.html#image-builder-IAM-prereq)。

**你的角色需要：**
+ 包括 Amazon EC2 服务的信任关系。
+ AmazonS3 ReadOnlyAccess、亚马逊SSMManagedInstanceCore 和 EC2InstanceProfileForImageBuilder 政策。

## 创建 EC2 Image Builder 组件
<a name="image-builder-component"></a>

按照《Image [Builder *用户指南》中的说明使用 Image Builder* 控制台创建组件](https://docs.aws.amazon.com/imagebuilder/latest/userguide/create-component-console.html)。

**输入您的组件详细信息：**

1. 对于 “**类型**”，选择 “**构建**”。

1. 对于**映像操作系统 (OS)**，请选择 Linux 或 Windows。

1. 在 “**组件名称**” 中，输入一个有意义的名称，例如**research-and-engineering-studio-vdi-<operating-system>**。

1. 输入组件的版本号，也可以添加描述。

   ```
   key : value 
   ```

1. 在**定义文档**中，输入以下定义文件。如果您遇到任何错误，那么 YAML 文件对空间很敏感，很可能是原因。
**重要**  
在定义文件中，如果您的 RES 环境版本不是最新版本，请将下载 URI (`- source: 's3://research-engineering-studio-us-east-1/releases/latest/res-installation-scripts.tar.gz'`**2025.06**) **latest** 中的替换为确切的版本号（例如）。

------
#### [ Linux ]

   ```
   #  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   #
   #  Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
   #  with the License. A copy of the License is located at
   #
   #      http://www.apache.org/licenses/LICENSE-2.0
   #
   #  or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
   #  OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
   #  and limitations under the License.
   name: research-and-engineering-studio-vdi-linux
   description: An RES EC2 Image Builder component to install required RES software dependencies for Linux VDI.
   schemaVersion: 1.0
   parameters:
     - GPUFamily:
         type: string
         description: GPU family (NONE, NVIDIA, or AMD)
         default: NONE
   phases:
     - name: build
       steps:
         - name: PrepareRESBootstrap
           action: ExecuteBash
           onFailure: Abort
           maxAttempts: 3
           inputs:
             commands:
               - "mkdir -p /root/bootstrap/logs"
               - "mkdir -p /root/bootstrap/latest"
         - name: DownloadRESLinuxInstallPackage
           action: S3Download
           onFailure: Abort
           maxAttempts: 3
           inputs:
             - source: "s3://research-engineering-studio-us-east-1/releases/latest/res-installation-scripts.tar.gz"
               destination: "/root/bootstrap/res-installation-scripts/res-installation-scripts.tar.gz"
         - name: RunInstallScript
           action: ExecuteBash
           onFailure: Abort
           maxAttempts: 3
           inputs:
             commands:
               - "cd /root/bootstrap/res-installation-scripts"
               - "tar -xf res-installation-scripts.tar.gz"
               - "cd scripts/virtual-desktop-host/linux"
               - "/bin/bash install.sh -g {{ GPUFamily }}"
         - name: RebootAfterInstall
           action: Reboot
           onFailure: Abort
           maxAttempts: 3
           inputs:
               delaySeconds: 0
         - name: RunInstallPostRebootScript
           action: ExecuteBash
           onFailure: Abort
           maxAttempts: 3
           inputs:
             commands:
               - "cd /root/bootstrap/res-installation-scripts/scripts/virtual-desktop-host/linux"
               - 'sed -i ''/^export AWS_DEFAULT_PROFILE="bootstrap_profile"$/d'' install_post_reboot.sh'
               - "/bin/bash install_post_reboot.sh -g {{ GPUFamily }}"
         - name: PreventAL2023FromUninstallingCronie
           action: ExecuteBash
           onFailure: Abort
           maxAttempts: 3
           inputs:
             commands:
               - "rm -f /tmp/imagebuilder_service/crontab_installed"
   ```

------
#### [ Windows ]

   ```
   #  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   #
   #  Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
   #  with the License. A copy of the License is located at
   #
   #      http://www.apache.org/licenses/LICENSE-2.0
   #
   #  or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
   #  OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
   #  and limitations under the License.
   name: research-and-engineering-studio-vdi-windows
   description: An RES EC2 Image Builder component to install required RES software dependencies for Windows VDI.
   schemaVersion: 1.0
   
   phases:
     - name: build
       steps:
          - name: CreateRESBootstrapFolder
            action: CreateFolder
            onFailure: Abort
            maxAttempts: 3
            inputs:
               - path: 'C:\Users\Administrator\RES\Bootstrap'
                 overwrite: true
          - name: DownloadRESWindowsInstallPackage
            action: S3Download
            onFailure: Abort
            maxAttempts: 3
            inputs:
               - source: 's3://research-engineering-studio-us-east-1/releases/latest/res-installation-scripts.tar.gz'
                 destination: '{{ build.CreateRESBootstrapFolder.inputs[0].path }}\res-installation-scripts.tar.gz'
          - name: RunInstallScript
            action: ExecutePowerShell
            onFailure: Abort
            maxAttempts: 3
            inputs:
               commands:
                   - 'cd {{ build.CreateRESBootstrapFolder.inputs[0].path }}'
                   - 'tar -xf res-installation-scripts.tar.gz'
                   - 'Import-Module .\scripts\virtual-desktop-host\windows\Install.ps1'
                   - 'Install-WindowsEC2Instance -PrebakeAMI'
   ```

------

1. 创建任何可选标签，然后选择**创建组件**。

## 准备好您的 EC2 Image Builder 配方
<a name="prepare-recipe"></a>

EC2 Image Builder 配方定义了作为创建新映像起点的基础映像，以及定义了您添加的一组用于自定义映像并验证一切是否按预期运行的组件。您必须创建或修改配方才能构造具有必要的 RES 软件依赖项的目标 AMI。有关食谱的更多信息，请参阅[管理食谱](https://docs.aws.amazon.com/imagebuilder/latest/userguide/manage-recipes.html)。

RES 支持以下镜像操作系统：
+ 亚马逊 Linux 2 (x86 和 ARM64)
+ 亚马逊 Linux 2023 (x86 和 ARM64) 
+ RHEL 8 (x86) 和 9 (x86)
+ Rocky Linux 9 (x86)
+ Ubuntu 22.04.3 (x86)
+ Ubuntu 24.04.3 (x86)
+ Windows Server 2019、2022 (x86)
+ Windows 10、11 (x86)

**注意**  
从 2026.03 版本开始，亚马逊 Linux 2 和 RHEL 8 不再包含在默认软件堆栈中。如果需要，仍然可以注册带有这些操作系统的自定义软件堆栈。

------
#### [ Create a new recipe ]

1. 打开 EC2 Image Builder 控制台，网址为[https://console.aws.amazon.com/imagebuilder](https://console.aws.amazon.com/imagebuilder)。

1. 在 “**已保存的资源**” 下，选择**图片配方**。

1. 选择**创建映像配方**。

1. 输入唯一的名称和版本号。

1. 选择 RES 支持的基础镜像。

1. 在 “**实例配置”** 下，如果未预安装 SSM 代理，请安装。在**用户数据**和任何其他需要的用户数据中输入信息。
**注意**  
有关如何安装 SSM 代理的信息，请参阅：  
在@@ [适用于 Linux 的 EC2 实例上手动安装 SSM 代理](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-manual-agent-install.html)。
在 [Windows 服务器的 EC2 实例上手动安装和卸载 SSM 代理。](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-win.html)

1. 对于基于 Linux 的配方，请将亚马逊管理的`aws-cli-version-2-linux`构建组件添加到配方中。对于基于 Windows 的配方，请将亚马逊管理的`aws-cli-version-2-windows`构建组件添加到配方中。RES 安装脚本使用提供对 DynamoDB 集群设置配置值的 VDI 访问权限。 AWS CLI 

1. 添加为您的 Linux 或 Windows 环境创建的 EC2 Image Builder 组件。
**重要**  
必须按顺序添加这些组件，并首先添加`aws-cli-version-2-linux`（对于 Linux）或` aws-cli-version-2-windows`（对于 Windows）构建组件。  

![\[显示已添加构建组件的 “组件” 页面\]](http://docs.aws.amazon.com/zh_cn/res/latest/ug/images/res-ami-build-components.png)


1. （推荐）添加亚马逊管理的`simple-boot-test-<linux-or-windows>`测试组件以验证 AMI 是否可以启动。这是最低限度的建议。您可以选择其他符合您要求的测试组件。

1. 如果需要，请完成所有可选部分，添加任何其他所需的组件，然后选择 “**创建配方**”。

------
#### [ Modify a recipe ]

如果您已有 EC2 Image Builder 配方，则可以通过添加以下组件来使用它：

1. 对于基于 Linux 的配方，请将亚马逊管理的`aws-cli-version-2-linux`构建组件添加到配方中。对于基于 Windows 的配方，请将亚马逊管理的`aws-cli-version-2-windows`构建组件添加到配方中。RES 安装脚本使用提供对 DynamoDB 集群设置配置值的 VDI 访问权限。 AWS CLI 

1. 添加为您的 Linux 或 Windows 环境创建的 EC2 Image Builder 组件。
**重要**  
必须按顺序添加这些组件，并首先添加`aws-cli-version-2-linux`（对于 Linux）或` aws-cli-version-2-windows`（对于 Windows）构建组件。  

![\[显示已添加构建组件的 “组件” 页面\]](http://docs.aws.amazon.com/zh_cn/res/latest/ug/images/res-ami-build-components.png)


1. 如果需要，请完成所有可选部分，添加任何其他所需的组件，然后选择 “**创建配方**”。

------

## 配置 EC2 Image Builder 基础架构
<a name="configure-ib-infrastructure"></a>

您可以使用基础设施配置来指定 Image Builder 用来构建和测试您的映像生成器映像的 Amazon EC2 基础架构。要与 RES 配合使用，您可以选择创建新的基础架构配置，也可以选择使用现有基础架构配置。
+ 要创建新的基础架构配置，请参阅[创建基础架构配置](https://docs.aws.amazon.com/imagebuilder/latest/userguide/create-infra-config.html)。
+ 要使用现有基础架构配置，[请更新基础架构配置](https://docs.aws.amazon.com/imagebuilder/latest/userguide/update-infra-config.html)。

**要配置 Image Builder 基础设施，请执行以下操作：**

1. 对于 **IAM 角色**，请输入您之前在中配置的角色[准备一个 IAM 角色以访问 RES 环境](#prepare-role)。

1. 对于**实例类型**，请选择内存至少 4 GB 且支持所选基本 AMI 架构的类型。参见 [Amazon EC2 实例类型](https://aws.amazon.com/ec2/instance-types/)。

1. 对于 **VPC、子网和安全组**，您必须允许互联网访问才能下载软件包。还必须允许访问 RES 环境的 `cluster-settings` DynamoDB 表和 Amazon S3 集群存储桶。

## 配置 Image Builder 图像管道
<a name="image-builder-pipeline"></a>

Image Builder 映像管道汇集了基础映像、用于构建和测试的组件、基础架构配置和分发设置。要将图像管道配置为 RES-ready AMIs，您可以选择创建新管道或使用现有管道。有关更多信息，请参阅 Image *Builder 用户指南中的创建和更新 AMI 图像*[管道](https://docs.aws.amazon.com/imagebuilder/latest/userguide/ami-image-pipelines.html)。

------
#### [ Create a new Image Builder pipeline ]

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

1. 在导航窗格中，选择**图像管道**。

1. 选择 “**创建图像管道**”。

1. 通过输入唯一名称、可选描述、计划和频率来指定您的管道详细信息。

1. **在 “选择食谱**” 中，选择 “**使用现有食谱**”，然后选择在中创建的配方[准备好您的 EC2 Image Builder 配方](#prepare-recipe)。验证您的食谱详细信息是否正确。

1. 对于**定义图像创建流程**，请根据用例选择默认或自定义工作流程。在大多数情况下，默认工作流程就足够了。有关更多信息，请参阅[为您的 EC2 Image Builder 管道配置图像工作流程](https://docs.aws.amazon.com/imagebuilder/latest/userguide/pipeline-workflows.html)。

1. 对于**定义基础架构配置**，选择**选择现有基础架构配置**，然后选择在中创建的基础架构配置[配置 EC2 Image Builder 基础架构](#configure-ib-infrastructure)。验证您的基础架构详细信息是否正确。

1. 在 “**定义分发设置” 中**，选择 “**使用服务默认值创建分发设置”**。输出图像必须与您的 RES 环境 AWS 区域 相同。使用服务默认值，将在使用 Image Builder 的区域创建图像。

1. 查看管道详细信息并选择**创建管道**。

------
#### [ Modify an existing Image Builder pipeline ]

1. 要使用现有管道，请修改详细信息以使用中创建的配方[准备好您的 EC2 Image Builder 配方](#prepare-recipe)。

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

------

## 运行 Image Builder 图像管道
<a name="run-image-pipeline"></a>

要生成配置的输出图像，必须启动图像管道。构建过程可能需要长达一个小时，具体取决于图像配方中组件的数量。

**要运行图像管道，请执行以下操作：**

1. 从**图像管道**中，选择在中创建的管道[配置 Image Builder 图像管道](#image-builder-pipeline)。

1. 从 “**操作**” 中选择 “**运行管道**”。

## 在 RES 中注册新的软件堆栈
<a name="register-res-ready-stack"></a>

1. 按照中的[软件堆栈 () AMIs](software-stacks.md)说明注册软件堆栈。

1. 对于 **AMI ID**，请输入内置输出映像的 AMI ID [运行 Image Builder 图像管道](#run-image-pipeline)。