

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 設定 RES 就緒 AMIs
<a name="res-ready-ami"></a>

透過支援 RES 的 Amazon Machine Image (AMIs)，您可以在自訂 AMI 上預先安裝虛擬桌面執行個體 VDIs) 的 RES AMIs 相依性。使用 RES-ready AMIs 可改善使用預先製作映像的 VDI 執行個體開機時間。使用 EC2 Image Builder，您可以將 AMIs 建置並註冊為新的軟體堆疊。如需映像建置器的詳細資訊，請參閱[映像建置器使用者指南](https://docs.aws.amazon.com/imagebuilder/latest/userguide/what-is-image-builder.html)。

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

**重要**  
在 RES 2025.06.01 之前建立的 RES 就緒 AMIs 與 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-pipeline)
+ [執行映像建置器映像管道](#run-image-pipeline)
+ [在 RES 中註冊新的軟體堆疊](#register-res-ready-stack)

## 準備 IAM 角色以存取 RES 環境
<a name="prepare-role"></a>

若要從 EC2 Image Builder 存取 RES 環境服務，您必須建立或修改名為 RES-EC2InstanceProfileForImageBuilder 的 IAM 角色。如需有關設定 IAM 角色以在映像建置器中使用的資訊，請參閱《*映像建置器使用者指南*》中的 [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 服務的信任關係。
+ AmazonS3ReadOnlyAccess、AmazonSSMManagedInstanceCore 和 EC2InstanceProfileForImageBuilder 政策。

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

遵循《[映像建置器使用者指南》中的指示，使用映像建置器主控台建立元件](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'`) **latest**中的 取代為確切的版本編號 （例如 **2025.06**)。

------
#### [ 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 支援下列映像作業系統：
+ Amazon Linux 2 (x86 和 ARM64)
+ Amazon 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 版開始，Amazon 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 Server 的 EC2 執行個體上手動安裝和解除安裝 SSM Agent](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-win.html)。

1. 對於 Linux 型配方，將 Amazon 受管`aws-cli-version-2-linux`建置元件新增至配方。對於以 Windows 為基礎的配方，將 Amazon 受管`aws-cli-version-2-windows`建置元件新增至配方。RES 安裝指令碼使用 AWS CLI 提供 DynamoDB 叢集設定組態值的 VDI 存取權。

1. 新增為 Linux 或 Windows 環境建立的 EC2 Image Builder 元件。
**重要**  
您必須先新增 `aws-cli-version-2-linux`（適用於 Linux) 或 ` aws-cli-version-2-windows`（適用於 Windows) 組建元件，才能依序新增這些元件。  

![\[元件頁面顯示已新增的建置元件\]](http://docs.aws.amazon.com/zh_tw/res/latest/ug/images/res-ami-build-components.png)


1. （建議） 新增 Amazon 受管`simple-boot-test-<linux-or-windows>`測試元件，以確認可以啟動 AMI。這是最低建議。您可以選取其他符合您需求的測試元件。

1. 視需要完成任何選用區段，新增任何其他所需的元件，然後選擇**建立配方**。

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

如果您有現有的 EC2 Image Builder 配方，您可以新增下列元件來使用它：

1. 對於 Linux 型配方，將 Amazon 受管`aws-cli-version-2-linux`建置元件新增至配方。對於以 Windows 為基礎的配方，將 Amazon 受管`aws-cli-version-2-windows`建置元件新增至配方。RES 安裝指令碼使用 AWS CLI 提供 DynamoDB 叢集設定組態值的 VDI 存取權。

1. 新增為 Linux 或 Windows 環境建立的 EC2 Image Builder 元件。
**重要**  
您必須先新增 `aws-cli-version-2-linux`（適用於 Linux) 或 ` aws-cli-version-2-windows`（適用於 Windows) 組建元件，才能依序新增這些元件。  

![\[元件頁面顯示已新增的建置元件\]](http://docs.aws.amazon.com/zh_tw/res/latest/ug/images/res-ami-build-components.png)


1. 視需要完成任何選用區段，新增任何其他所需的元件，然後選擇**建立配方**。

------

## 設定 EC2 Image Builder 基礎設施
<a name="configure-ib-infrastructure"></a>

您可以使用基礎設施組態來指定映像建置器用來建置和測試映像建置器映像的 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 叢集儲存貯體。

## 設定映像建置器映像管道
<a name="image-builder-pipeline"></a>

映像建置器映像管道會組合基礎映像、用於建置和測試的元件、基礎設施組態和分發設定。若要為 RES 就緒 AMIs 設定映像管道，您可以選擇建立新的管道，或使用現有的管道。如需詳細資訊，請參閱[《映像建置器使用者指南》中的建立和更新 AMI 映像管道](https://docs.aws.amazon.com/imagebuilder/latest/userguide/ami-image-pipelines.html)。 **

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

1. 在 開啟映像建置器主控台[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 區域 相同的 中。使用服務預設值，會在使用映像建置器的區域中建立映像。

1. 檢閱管道詳細資訊，然後選擇**建立管道**。

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

1. 若要使用現有的管道，請修改詳細資訊以使用在 中建立的配方[準備您的 EC2 Image Builder 配方](#prepare-recipe)。

1. 選擇**儲存變更**。

------

## 執行映像建置器映像管道
<a name="run-image-pipeline"></a>

若要產生設定的輸出映像，您必須啟動映像管道。建置程序可能需要長達一小時的時間，具體取決於映像配方中的元件數量。

**若要執行映像管道：**

1. 從**映像管道中**，選取在 中建立的管道[設定映像建置器映像管道](#image-builder-pipeline)。

1. 在**動作**中，選擇**執行管道**。

## 在 RES 中註冊新的軟體堆疊
<a name="register-res-ready-stack"></a>

1. 遵循 中的指示[軟體堆疊 (AMIs)](software-stacks.md)來註冊軟體堆疊。

1. 針對 **AMI ID**，輸入內建於 之輸出映像的 AMI ID[執行映像建置器映像管道](#run-image-pipeline)。