Skip to main content

2026 年 12 月 1 日

配置 Amazon Core 受管实例的资源

**功能状态:**有限可用性 (LA)

概览

要将 Amazon Core 受管实例 (CMI) 与 Horizon Cloud 结合使用,必须通过将支持的 Windows ISO 导入到 AWS 中、使用 EC2 Image Builder 创建基础 AMI,然后使用 EC2 Image Builder 组件、映像方法和管道通过 Horizon Agent Installer (HAI) 自定义该 AMI,来准备 Windows 映像。

本主题介绍通用准备步骤和特定于 CMI 的映像自定义工作流。

**注意:**此方法不同于 Amazon WorkSpaces Core 方法(方法 1:AWS EC2 自定义实例导入、方法 2 和方法 3)。请勿将此处所述的步骤与这些方法混用,因为两者的工作流不同。

通用准备步骤

需要先按顺序完成以下准备任务,然后才能为 CMI 创建 Windows 映像。这些步骤可确保您的环境、权限和源映像已准备就绪且可与 AWS EC2 Image Builder 一起使用。

有关每个步骤的详细过程,请参阅为 Horizon on AWS 创建 Windows 映像的通用准备步骤。

  1. 获取 Horizon on AWS 支持的 Windows ISO - 从 Microsoft 官方网站下载支持的 Windows ISO(例如,Windows 11 企业版 25H2 或 24H2)。

  2. 将 Windows ISO 上载到 Amazon S3 存储桶 - 将 ISO 文件上载到 AWS Image Builder 可访问的 Amazon S3 存储桶。ISO 文件扩展名必须为大写字母(例如,Windows11.ISO)。

  3. 为 EC2 Image Builder 创建 IAM 角色 - 使用以下权限策略创建 IAM 角色:

    • AmazonSSMManagedInstanceCore
    • EC2InstanceProfileForImageBuilder
    • EC2InstanceProfileForImageBuilderECRContainerBuilds
  4. 创建 EC2 Image Builder 基础架构配置 - 定义在映像构建和测试过程中使用的计算、网络连接和通知设置,包括实例类型、VPC、子网、安全组和 SNS 主题。

导入 Windows ISO 并创建基础 AMI

完成通用准备步骤后,使用 EC2 Image Builder 将 Windows ISO 导入到 AWS 中,以创建基础 Amazon 计算机映像 (AMI)。生成的 AMI 稍后将用作映像方法的父映像。

步骤

  1. 从 AWS 管理控制台中,转到 EC2 Image Builder。
  2. 在导航窗格中,选择映像。
  3. 选择导入映像。
  4. 在常规部分中,提供以下信息:
    • 名称 - 输入映像的唯一名称。
    • 版本 - 使用 major.minor.patch 格式指定版本号。
  5. 对于导入类型,选择 ISO 导入。
  6. 在 ISO 导入配置部分中,提供以下详细信息:
    • S3 URI - 指定存储 Windows ISO 文件的 Amazon S3 位置。
    • IAM 角色 - 选择在通用准备步骤中创建的 IAM 角色。
  7. 对于 ISO 基础架构配置,选择在通用准备步骤中创建的基础架构配置。
  8. 选择导入映像以启动 ISO 导入过程。
  9. 在 EC2 Image Builder 中监控导入状态,直到映像创建成功完成。

验证基础 AMI

ISO 导入完成后,验证基础 AMI 是否可用,然后再继续:

  1. 在 EC2 Image Builder 中,导航到映像。
  2. 找到从 ISO 导入创建的映像。
  3. 确认上次成功状态显示为可用。

使用 Horizon Agent Installer 自定义 Windows AMI

创建并验证基础 AMI 后,使用 EC2 Image Builder 组件、映像方法和映像管道通过 Horizon Agent Installer 对其进行自定义。此方法可自动执行自定义,而无需手动进行 RDP 会话。

步骤 1:创建自定义 EC2 Image Builder 组件

在 EC2 Image Builder 中创建自定义组件,以自动安装 Horizon Agent 并配置 OOBE 设置。每个组件均定义为一个 YAML 文档。

要创建自定义组件,请执行以下操作:

  1. 在 EC2 Image Builder 中,导航到组件,然后单击创建组件。
  2. 对于映像操作系统,选择 Windows。操作系统版本由 ISO 确定,无需指定。
  3. 将 KMS 服务器保留为默认值。
  4. 使用 YAML 文档格式定义组件内容。
  5. 单击创建组件。

创建以下四个组件。这些组件添加到映像方法中的顺序(在下一步中)至关重要。

组件 1:安装前 RunOnce 备份

将所有 HKLM RunOnce 密钥(64 位和 Wow6432Node)备份到 C:\Windows\Temp,然后移除所有 RunOnce 值,以便 Horizon Agent Installer 不会检测到挂起的重新引导(退出 0x643)。紧接在 Horizon Agent 安装组件之前运行此组件。

# DISCLAIMER:
# This script/YAML file is provided as a sample for reference purposes only.
# It is not intended for production use without proper review, testing, and validation.
# Users are responsible for evaluating and modifying the content to meet their
# security, compliance, and operational requirements.
# No warranties or guarantees are provided.

name: HorizonAgentPreInstallRunOnceBackup
description: Backs up all HKLM RunOnce keys/values (64-bit and Wow6432Node) to C:\Windows\Temp, then removes all RunOnce values so the Horizon Agent installer does not detect a pending reboot (exit 0x643). Run immediately before the Horizon Agent install component.
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ShowRunOnceValues
        action: ExecutePowerShell
        onFailure: Continue
        inputs:
          commands:
            - |
              foreach ($p in 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce',
                             'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\RunOnce') {
                  Write-Host "== $p =="
                  Get-ItemProperty -Path $p -ErrorAction SilentlyContinue | Format-List
              }

      - name: BackupAllRunOnceKeys
        action: ExecutePowerShell
        onFailure: Abort
        inputs:
          commands:
            - |
              $targets = @(
                  @{ Reg = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce';             Ps = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce';             File = 'C:\Windows\Temp\RunOnce_HKLM_backup' },
                  @{ Reg = 'HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\RunOnce'; Ps = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\RunOnce'; File = 'C:\Windows\Temp\RunOnce_HKLM_Wow6432Node_backup' }
              )

              foreach ($t in $targets) {
                  if (-not (Test-Path $t.Ps)) {
                      Write-Host "Key not present, skipping: $($t.Reg)"
                      continue
                  }

                  $regFile = "$($t.File).reg"
                  & reg.exe export $t.Reg $regFile /y
                  if ($LASTEXITCODE -ne 0) { Write-Error "reg export failed ($LASTEXITCODE) for $($t.Reg)"; exit 1 }
                  if (-not (Test-Path $regFile)) { Write-Error "Backup file not found: $regFile"; exit 1 }
                  Write-Host "Backup written to $regFile"

                  $jsonFile = "$($t.File).json"
                  $items = @(Get-Item -Path $t.Ps) + @(Get-ChildItem -Path $t.Ps -Recurse -ErrorAction SilentlyContinue)
                  $rows = foreach ($k in $items) {
                      foreach ($n in $k.GetValueNames()) {
                          [pscustomobject]@{
                              Key   = $k.Name
                              Name  = $n
                              Type  = $k.GetValueKind($n).ToString()
                              Value = $k.GetValue($n, $null, 'DoNotExpandEnvironmentNames')
                          }
                      }
                  }
                  @($rows) | ConvertTo-Json -Depth 4 | Set-Content -Path $jsonFile -Encoding UTF8
                  Write-Host "Value inventory written to $jsonFile ($(@($rows).Count) values)"
              }

      - name: RemoveAllRunOnceValues
        action: ExecutePowerShell
        onFailure: Abort
        inputs:
          commands:
            - |
              # SAFETY: $true = log only (dry run). Set to $false to actually delete.
              $DryRun = $false

              $roots = @(
                  'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce',
                  'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\RunOnce'
              )

              foreach ($root in $roots) {
                  if (-not (Test-Path $root)) { Write-Host "Key not present, skipping: $root"; continue }

                  # Root key plus any subkeys (e.g. RunOnce\Setup). Subkeys themselves are kept; only values are removed.
                  $keys = @(Get-Item -Path $root) + @(Get-ChildItem -Path $root -Recurse -ErrorAction SilentlyContinue)
                  foreach ($k in $keys) {
                      foreach ($n in $k.GetValueNames()) {
                          if ([string]::IsNullOrEmpty($n)) { continue }   # skip (Default)
                          if ($DryRun) {
                              Write-Host "[DRY RUN] Would remove '$n' from $($k.Name)"
                          } else {
                              Remove-ItemProperty -LiteralPath $k.PSPath -Name $n -ErrorAction Stop
                              Write-Host "Removed '$n' from $($k.Name)"
                          }
                      }
                  }
              }
              exit 0

组件 2:安装 Omnissa Horizon Agent

下载并无提示安装 Omnissa Horizon Agents Installer。该安装程序具有恢复能力 -- 如果遇到 1603 错误,它会重新引导并重试(最多 2 次)。

# DISCLAIMER:
# This script/YAML file is provided as a sample for reference purposes only.
# It is not intended for production use without proper review, testing, and validation.
# Users are responsible for evaluating and modifying the content to meet their
# security, compliance, and operational requirements.
# No warranties or guarantees are provided.

name: InstallOmnissaHorizonAgents
description: Downloads and silently installs Omnissa Horizon Agents Installer 26.3.0 (resilient, reboot-and-retry on 1603)
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: CheckPendingReboot
        action: ExecutePowerShell
        onFailure: Continue
        inputs:
          commands:
            - |
              $pending = @()
              if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending') { $pending += 'CBS' }
              if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') { $pending += 'WindowsUpdate' }
              $pfro = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name PendingFileRenameOperations -ErrorAction SilentlyContinue).PendingFileRenameOperations
              if ($pfro) { $pending += 'PendingFileRename' }
              if ($pending.Count -gt 0) {
                Write-Warning "Pending reboot detected ($($pending -join ', ')). Skipping reboot and continuing installation."
              } else {
                Write-Host "No pending reboot detected."
              }
              exit 0

      - name: DownloadHorizonAgents
        action: WebDownload
        maxAttempts: 3
        timeoutSeconds: 1800
        onFailure: Abort
        inputs:
          - source: https://softwareupdate.omnissa.com/horizoncloud-v2-agents/packages/HAI-Agent/26.3.0/40775428445/Omnissa-Horizon-Agents-Installer-26.3.0-40775428445-x64.exe
            destination: C:\Windows\Temp\Omnissa-Horizon-Agents-Installer.exe
            overwrite: true

      - name: InstallHorizonAgents
        action: ExecutePowerShell
        maxAttempts: 2
        timeoutSeconds: 3600
        onFailure: Abort
        inputs:
          commands:
            - |
              $ErrorActionPreference = 'Stop'
              $installer = 'C:\Windows\Temp\Omnissa-Horizon-Agents-Installer.exe'
              $sourceUrl = 'https://softwareupdate.omnissa.com/horizoncloud-v2-agents/packages/HAI-Agent/26.3.0/40775428445/Omnissa-Horizon-Agents-Installer-26.3.0-40775428445-x64.exe'
              $log       = 'C:\Windows\Temp\HorizonAgents_install_wrapper.log'
              $retryFile = 'C:\Windows\Temp\HorizonAgents_1603_retry.txt'   # survives reboot
              $maxRebootRetries = 2

              function Log($m) { "$(Get-Date -Format s) $m" | Out-File $log -Append; Write-Host $m }

              $retryCount = 0
              if (Test-Path $retryFile) { $retryCount = [int](Get-Content $retryFile -Raw) }
              if ($retryCount -gt 0) { Log "Resuming after reboot (1603 retry #$retryCount)." }

              # Idempotency check - skipped during 1603 retries (failed installs can leave partial uninstall entries)
              if ($retryCount -eq 0) {
                $keys = @(
                  'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
                  'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
                )
                $existing = Get-ItemProperty $keys -ErrorAction SilentlyContinue |
                  Where-Object { $_.DisplayName -like '*Omnissa Horizon*' }
                if ($existing) { Log "Already installed: $($existing.DisplayName -join ', '). Skipping."; exit 0 }
              }

              # Re-download if installer is missing after reboot
              if (-not (Test-Path $installer)) {
                Log "Installer missing. Re-downloading..."
                [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
                Invoke-WebRequest -Uri $sourceUrl -OutFile $installer -UseBasicParsing
                if (-not (Test-Path $installer)) { Log "ERROR: Re-download failed."; exit 1 }
              }

              Log "Starting install..."
              $p = Start-Process -FilePath $installer -ArgumentList '/silent','/norestart' -Wait -PassThru
              $code = $p.ExitCode
              Log "Installer exit code: $code"

              switch ($code) {
                0    { Remove-Item $retryFile -Force -ErrorAction SilentlyContinue; Log "Install succeeded."; exit 0 }
                3010 { Remove-Item $retryFile -Force -ErrorAction SilentlyContinue; Log "Install succeeded; reboot handled by next step."; exit 0 }
                1641 { Remove-Item $retryFile -Force -ErrorAction SilentlyContinue; Log "Install succeeded; installer initiated reboot."; exit 0 }
                1603 {
                  if ($retryCount -lt $maxRebootRetries) {
                    $retryCount++
                    Set-Content -Path $retryFile -Value $retryCount
                    Log "1603 received. Rebooting and retrying ($retryCount of $maxRebootRetries)..."
                    exit 3010   # AWSTOE: reboot the instance, then re-run this step
                  }
                  Log "ERROR: 1603 persisted after $maxRebootRetries reboot/retry cycles."
                  Remove-Item $retryFile -Force -ErrorAction SilentlyContinue
                  exit 1603
                }
                default { Log "ERROR: Install failed with exit code $code"; exit $code }
              }

      - name: RebootAfterInstall
        action: Reboot
        onFailure: Continue
        inputs:
          delaySeconds: 30

      - name: CleanupInstaller
        action: ExecutePowerShell
        onFailure: Continue
        inputs:
          commands:
            - |
              Remove-Item 'C:\Windows\Temp\Omnissa-Horizon-Agents-Installer.exe' -Force -ErrorAction SilentlyContinue
              Remove-Item 'C:\Windows\Temp\HorizonAgents_1603_retry.txt' -Force -ErrorAction SilentlyContinue
              exit 0

  - name: validate
    steps:
      - name: VerifyInstallation
        action: ExecutePowerShell
        onFailure: Continue
        inputs:
          commands:
            - |
              $keys = @(
                'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
                'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
              )
              $found = Get-ItemProperty $keys -ErrorAction SilentlyContinue |
                Where-Object { $_.DisplayName -like '*Omnissa Horizon*' }
              if ($found) {
                $found | ForEach-Object { Write-Host "Installed: $($_.DisplayName) $($_.DisplayVersion)" }
              } else {
                Write-Warning "Omnissa Horizon Agents not found"
              }
              exit 0

组件 3:安装后 RunOnce 还原

从安装前备份组件创建的 C:\Windows\Temp 备份中还原所有 HKLM RunOnce 密钥,根据值清单验证密钥,然后重新引导。

# DISCLAIMER:
# This script/YAML file is provided as a sample for reference purposes only.
# It is not intended for production use without proper review, testing, and validation.
# Users are responsible for evaluating and modifying the content to meet their
# security, compliance, and operational requirements.
# No warranties or guarantees are provided.

name: HorizonAgentPostInstallRunOnceRestore
description: Restores all HKLM RunOnce keys/values (64-bit and Wow6432Node) from the C:\Windows\Temp backups created by HorizonAgentPreInstallRunOnceBackup after the Horizon Agent install, verifies them against the value inventory, then reboots.
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ImportRunOnceBackups
        action: ExecutePowerShell
        onFailure: Abort
        inputs:
          commands:
            - |
              $backups = @(
                  'C:\Windows\Temp\RunOnce_HKLM_backup.reg',
                  'C:\Windows\Temp\RunOnce_HKLM_Wow6432Node_backup.reg'
              )
              $imported = 0
              foreach ($b in $backups) {
                  if (-not (Test-Path $b)) {
                      # Backup step skips keys that did not exist, so a missing file is not an error
                      Write-Host "Backup not found, skipping: $b"
                      continue
                  }
                  & reg.exe import $b
                  if ($LASTEXITCODE -ne 0) { Write-Error "reg import failed ($LASTEXITCODE) for $b"; exit 1 }
                  Write-Host "Imported $b"
                  $imported++
              }
              if ($imported -eq 0) { Write-Error "No RunOnce backup files found in C:\Windows\Temp"; exit 1 }

      - name: VerifyRestoredRunOnceValues
        action: ExecutePowerShell
        onFailure: Continue
        inputs:
          commands:
            - |
              $inventories = @(
                  @{ Json = 'C:\Windows\Temp\RunOnce_HKLM_backup.json' },
                  @{ Json = 'C:\Windows\Temp\RunOnce_HKLM_Wow6432Node_backup.json' }
              )
              $missing = 0; $checked = 0
              foreach ($i in $inventories) {
                  if (-not (Test-Path $i.Json)) { Write-Host "Inventory not found, skipping: $($i.Json)"; continue }
                  $rows = @(Get-Content -Raw -Path $i.Json | ConvertFrom-Json)
                  foreach ($r in $rows) {
                      if ($null -eq $r -or [string]::IsNullOrEmpty($r.Name)) { continue }
                      $checked++
                      $psKey = 'Registry::' + $r.Key
                      $cur = Get-ItemProperty -LiteralPath $psKey -Name $r.Name -ErrorAction SilentlyContinue
                      if ($cur) { Write-Host "Restored: $($r.Key)\$($r.Name)" }
                      else      { Write-Warning "NOT restored: $($r.Key)\$($r.Name)"; $missing++ }
                  }
              }
              Write-Host "Checked $checked values; $missing missing"

      - name: RebootAfterRestore
        action: Reboot
        onFailure: Abort
        inputs:
          delaySeconds: 60

      - name: CleanupBackups
        action: ExecutePowerShell
        onFailure: Continue
        inputs:
          commands:
            - |
              Remove-Item -Path 'C:\Windows\Temp\RunOnce_HKLM_backup.reg',
                                'C:\Windows\Temp\RunOnce_HKLM_backup.json',
                                'C:\Windows\Temp\RunOnce_HKLM_Wow6432Node_backup.reg',
                                'C:\Windows\Temp\RunOnce_HKLM_Wow6432Node_backup.json' -Force -ErrorAction SilentlyContinue
              Write-Host "Backup files removed"

组件 4:配置 OOBE 无人参与

将 OOBE、UserAccounts、AutoLogon 和区域设置/键盘设置添加到 EC2Launch v2 Sysprep 无人参与文件中,以避免在安装过程中手动输入操作系统信息。

# DISCLAIMER:
# This script/YAML file is provided as a sample for reference purposes only.
# It is not intended for production use without proper review, testing, and validation.
# Users are responsible for evaluating and modifying the content to meet their
# security, compliance, and operational requirements.
# No warranties or guarantees are provided.

name: ConfigureOOBEUnattend
description: Adds OOBE, UserAccounts, AutoLogon and locale/keyboard settings to the EC2Launch v2 Sysprep unattend file
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: UpdateEC2LaunchUnattend
        action: ExecutePowerShell
        onFailure: Abort
        inputs:
          commands:
            - |
              $path = 'C:\ProgramData\Amazon\EC2Launch\sysprep\unattend.xml'
              if (-not (Test-Path $path)) { Write-Host "ERROR: $path not found"; exit 1 }
              Copy-Item $path "$path.bak" -Force

              [xml]$xml = Get-Content $path
              $uri = 'urn:schemas-microsoft-com:unattend'
              $ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
              $ns.AddNamespace('u', $uri)

              $shell = $xml.SelectSingleNode("//u:settings[@pass='oobeSystem']/u:component[@name='Microsoft-Windows-Shell-Setup']", $ns)
              if (-not $shell) { Write-Host "ERROR: oobeSystem Shell-Setup component not found"; exit 1 }

              # Create/set a nested element path under a parent, e.g. Set-Node $shell @('OOBE','HideEULAPage') 'true'
              function Set-Node($parent, [string[]]$names, [string]$value) {
                $cur = $parent
                foreach ($name in $names) {
                  $child = $cur.SelectSingleNode("u:$name", $ns)
                  if (-not $child) { $child = $xml.CreateElement($name, $uri); [void]$cur.AppendChild($child) }
                  $cur = $child
                }
                $cur.InnerText = $value
              }

              # Random throwaway password generated at build time (never logged, never stored in source).
              # EC2Launch resets the Administrator password at instance launch.
              $bytes = New-Object byte[] 18
              [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
              $pw = [Convert]::ToBase64String($bytes) + 'aA1!'

              # UserAccounts
              Set-Node $shell @('UserAccounts','AdministratorPassword','Value') $pw
              Set-Node $shell @('UserAccounts','AdministratorPassword','PlainText') 'true'

              # AutoLogon
              Set-Node $shell @('AutoLogon','Username') 'Administrator'
              Set-Node $shell @('AutoLogon','Enabled') 'true'
              Set-Node $shell @('AutoLogon','LogonCount') '1'
              Set-Node $shell @('AutoLogon','Password','Value') $pw
              Set-Node $shell @('AutoLogon','Password','PlainText') 'true'

              # OOBE
              $oobe = [ordered]@{
                HideEULAPage             = 'true'
                ProtectYourPC            = '3'
                HideWirelessSetupInOOBE  = 'true'
                HideOnlineAccountScreens = 'true'
                NetworkLocation          = 'Work'
              }
              foreach ($k in $oobe.Keys) { Set-Node $shell @('OOBE', $k) $oobe[$k] }

              # Locale / keyboard (pre-answers the Country, Keyboard layout and Second keyboard OOBE pages)
              $settingsNode = $shell.ParentNode
              $intl = $settingsNode.SelectSingleNode("u:component[@name='Microsoft-Windows-International-Core']", $ns)
              if (-not $intl) {
                $intl = $xml.CreateElement('component', $uri)
                $attrs = [ordered]@{ name='Microsoft-Windows-International-Core'; processorArchitecture='amd64'; publicKeyToken='31bf3856ad364e35'; language='neutral'; versionScope='nonSxS' }
                foreach ($a in $attrs.Keys) { $intl.SetAttribute($a, $attrs[$a]) }
                [void]$settingsNode.AppendChild($intl)
              }
              $locale = [ordered]@{
                InputLocale  = '0409:00000409'   # single US keyboard; no secondary layout page
                SystemLocale = 'en-US'
                UILanguage   = 'en-US'
                UserLocale   = 'en-US'           # sets country/region format
              }
              foreach ($k in $locale.Keys) { Set-Node $intl @($k) $locale[$k] }

              $xml.Save($path)
              Write-Host "Updated $path"

  - name: validate
    steps:
      - name: VerifyUnattendSettings
        action: ExecutePowerShell
        onFailure: Abort
        inputs:
          commands:
            - |
              $path = 'C:\ProgramData\Amazon\EC2Launch\sysprep\unattend.xml'
              [xml]$xml = Get-Content $path
              $ns = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
              $ns.AddNamespace('u', 'urn:schemas-microsoft-com:unattend')
              $base = "//u:settings[@pass='oobeSystem']/u:component[@name='Microsoft-Windows-Shell-Setup']"
              $ic   = "//u:settings[@pass='oobeSystem']/u:component[@name='Microsoft-Windows-International-Core']"

              $checks = [ordered]@{
                "$base/u:OOBE/u:HideEULAPage"             = 'true'
                "$base/u:OOBE/u:ProtectYourPC"            = '3'
                "$base/u:OOBE/u:HideWirelessSetupInOOBE"  = 'true'
                "$base/u:OOBE/u:HideOnlineAccountScreens" = 'true'
                "$base/u:OOBE/u:NetworkLocation"          = 'Work'
                "$base/u:AutoLogon/u:Username"            = 'Administrator'
                "$base/u:AutoLogon/u:Enabled"             = 'true'
                "$base/u:AutoLogon/u:LogonCount"          = '1'
                "$ic/u:InputLocale"                       = '0409:00000409'
                "$ic/u:SystemLocale"                      = 'en-US'
                "$ic/u:UILanguage"                        = 'en-US'
                "$ic/u:UserLocale"                        = 'en-US'
              }
              $failed = $false
              foreach ($xp in $checks.Keys) {
                $n = $xml.SelectSingleNode($xp, $ns)
                if (-not $n -or $n.InnerText -ne $checks[$xp]) { Write-Host "ERROR: missing/incorrect $xp"; $failed = $true }
              }
              # Presence-only checks for password nodes (values are never printed)
              foreach ($xp in @("$base/u:UserAccounts/u:AdministratorPassword/u:Value", "$base/u:AutoLogon/u:Password/u:Value")) {
                $n = $xml.SelectSingleNode($xp, $ns)
                if (-not $n -or [string]::IsNullOrEmpty($n.InnerText)) { Write-Host "ERROR: missing $xp"; $failed = $true }
              }
              if ($failed) { exit 1 }
              Write-Host "OOBE, UserAccounts, AutoLogon and locale settings present in $path"

步骤 2:创建映像方法

创建组件后,创建一个映像方法,按特定顺序将基础 AMI(从 ISO 导入中创建)与自定义组件组合在一起。

要创建映像方法,请执行以下操作:

  1. 在 EC2 Image Builder 中,导航到映像方法,然后单击创建方法。
  2. 选择从 ISO 导入创建的映像作为基础/父映像。
  3. 选择基础架构配置。
  4. 完全按照以下顺序添加构建组件:
顺序组件用途
1HorizonAgentPreInstallRunOnceBackup备份 RunOnce 密钥,以便 HAI 安装程序不会检测到挂起的重新引导
2InstallOmnissaHorizonAgents安装 Omnissa Horizon Agent
3HorizonAgentPostInstallRunOnceRestore还原备份的 RunOnce 密钥
4ConfigureOOBEUnattend配置 OOBE、自动登录和区域设置
  1. 选择分发设置。
  2. 单击创建方法。

**重要信息:**组件顺序至关重要。安装前 RunOnce 备份必须在 HAI 安装程序之前运行,以便安装程序不会检测到挂起的重新引导(退出 0x643)。安装后 RunOnce 还原必须在 HAI 安装程序之后运行,以还原备份的密钥。

步骤 3:创建映像管道

创建映像方法后,创建一个映像管道,将组件、方法和基础架构配置组合在一起,以生成最终的 AMI。

要创建映像管道,请执行以下操作:

  1. 在 EC2 Image Builder 中,导航到管道,然后单击创建管道。
  2. 在常规部分中,输入管道的名称。
  3. 选择执行类型:
    • 手动 - 按需运行管道。
    • 已计划 - 按计划运行管道。
  4. 选择映像方法及其版本。
  5. 确认组件按正确顺序列出(安装前 RunOnce → HAI → 安装后 RunOnce → OOBE)。
  6. 将工作流保留为默认值。
  7. 选择在通用准备步骤中创建的基础架构配置。
  8. 配置分发设置(使用现有设置或新建设置)。
  9. 单击创建管道。

管道工作流阶段:

  • 构建 - 启动构建实例,等待 SSM 代理就绪,运行构建组件,从自定义实例创建 AMI,然后终止构建实例。
  • 测试 - 从新 AMI 启动一个新实例,运行测试组件并收集结果。如果任何测试失败,则映像会被标记为失败。
  • 分发(可选)- 将 AMI 复制到目标区域并应用共享设置。

要运行管道,请执行以下操作:

  1. 选择管道,然后选择操作 > 运行管道。
  2. 工作流引擎会进行编排:构建 → 测试 → 分发。
  3. 要查看输出映像,请选择管道 > 输出映像 > 选择版本。在输出资源下,将显示 AMI ID。

有关构建 EC2 Image Builder 管道的更多指导,请参阅 AWS Builder Center 文章:为 Amazon WorkSpaces 构建 EC2 Image Builder 管道 -- 分步指南。

步骤 4:验证映像并在 Horizon Cloud IMS 中注册

管道完成后,验证映像并在 Horizon Cloud 中注册该映像以创建基于 CMI 的映像。

  1. 在 EC2 Image Builder 中,导航到管道并检查映像状态是否显示为可用。
  2. (可选)从创建的 AMI 启动测试实例以验证配置:
    • 选择 AMI,然后单击从 AMI 启动实例。
    • 提供密钥对详细信息。
    • 登录到该实例,并确认 Horizon Agent 和所有配置均正确无误。
  3. 验证后,在 Horizon Cloud 映像管理服务 (IMS) 中注册 AMI 以创建基于 CMI 的映像。有关详细信息,请参阅 Horizon Cloud Console 映像导入工作流。

**注意:**Horizon Cloud 中的 CMI 映像注册单独进行说明。有关注册过程,请参阅使用 AMI 注册 AWS CMI 映像。

相关参考

此页面对您有帮助吗?

对本主题提供反馈

本主题对您有帮助吗?

请勿填写任何个人信息或机密信息。

正在生成链接…