

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

# 为 Image Builder Windows 映像安装 Distributor 软件包托管组件应用程序
<a name="mgdcomponent-distributor-win"></a>

AWS Systems Manager Distributor 可以帮助您将软件打包并发布到 AWS Systems Manager 托管节点。您可以打包和发布自己的软件，也可以使用 Distributor 查找和发布 AWS提供的代理软件包。有关 Systems Manager Distributor 的更多信息，请参阅*《AWS Systems Manager 用户指南》*中的 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html)。

**Distributor 的托管组件**  
以下 Image Builder 托管组件使用 AWS Systems Manager Distributor 在 Windows 实例上安装应用程序包。
+ `distributor-package-windows` 托管组件使用 AWS Systems Manager Distributor 来安装您在 Windows 映像构建实例上指定的应用程序包。要在将此组件包含在配方中时配置参数，请参阅[配置 `distributor-package-windows` 为独立组件](#mgdcomponent-distributor-config-standalone)。
+ 该`aws-vss-components-windows`组件使用 Dist AWS Systems Manager ributor 在你的 Windows 映像生成实例上安装`AwsVssComponents`软件包。要在将此组件包含在配方中时配置参数，请参阅[配置 `aws-vss-components-windows` 为独立组件](#mgdcomponent-vss-config-standalone)。

有关如何在 Image Builder 配方中使用托管组件的更多信息，请参阅适用于映像配方的 [创建映像配方的新版本](create-image-recipes.md) 或适用于容器配方的 [创建新版本的容器配方](create-container-recipes.md)。有关 `AwsVssComponents` 软件包的更多信息，请参阅《Amazon EC2 用户指南》**中的[创建 VSS 应用程序一致性快照](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/application-consistent-snapshots.html)。

## 先决条件
<a name="mgdcomponent-distributor-prereq"></a>

在使用依赖 Systems Manager Distributor 的 Image Builder 组件安装应用程序包之前，必须确保满足以下先决条件。
+ 使用 Systems Manager Distributor 在您的实例上安装应用程序包的 Image Builder 组件需要获得调用 Systems Manager API 的权限。在您使用 Image Builder 配方中的组件之前，必须创建用于授予权限的 IAM policy 和角色。要配置权限，请参阅 [配置 Systems Manager Distributor 权限](#mgdcomponent-distributor-permissions)。

**注意**  
Image Builder 目前不支持重启实例的 Systems Manager Distributor 软件包。例如，`AWSNVMe`、`AWSPVDrivers` 和 `AwsEnaNetworkDriver` Distributor 软件包会重启实例，因此是不允许的。

## 配置 Systems Manager Distributor 权限
<a name="mgdcomponent-distributor-permissions"></a>

`distributor-package-windows` 组件和其他使用它的组件（例如 `aws-vss-components-windows`）需要获得构建实例的额外权限才能运行。构建实例必须能够调用 Systems Manager API 才能开始安装 Distributor 并轮询结果。

按照中的这些步骤创建自定义 IAM 策略和角色，该 AWS 管理控制台 策略和角色授予 Image Builder 组件从构建实例安装 Systems Manager Distributor 包的权限。

**步骤 1：创建策略**  
为 Distributor 权限创建 IAM policy。

1. 使用 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 打开 IAM 控制台。

1. 在导航窗格中，选择 **策略**，然后选择 **创建策略**。

1. 在**创建策略**页面上，选择 **JSON** 选项卡，然后将默认内容替换为以下 JSON 策略，根据需要替换分区、区域和账户 ID，或者使用通配符。

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "AllowDistributorSendCommand",
               "Effect": "Allow",
               "Action": "ssm:SendCommand",
               "Resource": [
                   "arn:aws:ssm:*::document/AWS-ConfigureAWSPackage",
                   "arn:aws:ec2:*:111122223333:instance/*"
               ]
           },
           {
               "Sid": "AllowGetCommandInvocation",
               "Effect": "Allow",
               "Action": "ssm:GetCommandInvocation",
               "Resource": "*"
           }
       ]
   }
   ```

------

1. 选择**查看策略**。

1. 对于**名称**，请输入一个名称以标识该策略，例如 `InvokeDistributor` 或您喜欢的其他名称。

1. （可选）对于**描述**，请输入该角色的用途描述。

1. 选择 **Create policy**。

**步骤 2：创建角色**  
为 Distributor 权限创建 IAM 角色。

1. 在 IAM 控制台导航窗格中，选择 **角色**，然后选择 **创建角色**。

1. 在**选择受信任实体的类型**下，选择 **AWS 服务**。

1. 在紧靠**选择将使用此角色的服务**下面，选择 **EC2**，然后选择**下一步: 权限**。

1. 在**选择您的使用案例**下面，选择 **EC2**，然后选择**下一步: 权限**。

1. 在政策列表中，选中 **Amazon** 旁边的复选框SSMManagedInstanceCore。（如果需要缩小列表范围，请在搜索框中键入 `SSM`。）

1. 在此策略列表中，选中旁边的复选框**EC2InstanceProfileForImageBuilder**。（如果需要缩小列表范围，请在搜索框中键入 `ImageBuilder`。）

1. 选择**下一步：标签**。

1. （可选）添加一个或多个标签键值对，以组织、跟踪或控制此角色的访问，然后选择 **下一步：审核**。

1. 对于**角色名称**，请输入角色的名称，例如 `InvokeDistributor` 或您喜欢的其他名称。

1. （可选）对于**角色描述**，请将默认文本替换为该角色的用途描述。

1. 选择 **Create role (创建角色)**。系统将让您返回到 **角色** 页面。

**步骤 3：向角色附加该策略**  
设置您的 Distributor 权限的最后一步是将您创建的 IAM policy 附加到 IAM 角色。

1. 在 IAM 控制台 **Roles（角色）**页面上，选择您刚刚创建的角色。将打开角色**摘要**页面。

1. 选择**附加策略**。​

1. 搜索在上一过程中创建的策略，然后选中该名称旁边的复选框。

1. 选择 **Attach policy**（附加策略）。

对于包含使用 Systems Manager Distributor 的组件的任何映像，在 Image Builder 基础设施配置资源中使用此角色。有关更多信息，请参阅 [创建基础设施配置](create-infra-config.md)。

## 配置 `distributor-package-windows` 为独立组件
<a name="mgdcomponent-distributor-config-standalone"></a>

要在配方中使用 `distributor-package-windows` 组件，请设置以下参数来配置要安装的程序包。

**注意**  
必须确保满足所有 [先决条件](#mgdcomponent-distributor-prereq)，才能在配方中使用 `distributor-package-windows` 组件。
+ **操作**（必需）- 指定是安装还是卸载软件包。有效值包括 `Install` 和 `Uninstall`。此值默认为 `Install`。
+ **PackageName**（必填）-要安装或卸载的分销商软件包的名称。有关有效软件包名称的列表，请参阅 [查找 Distributor 软件包](#mgdcomponent-distributor-find-pkg)。
+ **PackageVersion**（可选）-要安装的分销商软件包的版本。 PackageVersion 默认为推荐版本。
+ **AdditionalArguments**（可选）— 一个 JSON 字符串，其中包含要提供给脚本以安装、卸载或更新软件包的其他参数。有关更多信息，请参阅** Systems Manager 命令文档插件引用页面** [aws:configurePackage](https://docs.aws.amazon.com/systems-manager/latest/userguide/documents-command-ssm-plugin-reference.html#aws-configurepackage) **输入**章节中的 **additionalArguments**。

## 配置 `aws-vss-components-windows` 为独立组件
<a name="mgdcomponent-vss-config-standalone"></a>

在配方中使用 `aws-vss-components-windows` 组件时，可以选择设置 `PackageVersion` 参数，以使用 `AwsVssComponents` 程序包的特定版本。如果省略此参数，该组件将默认使用 `AwsVssComponents` 程序包的推荐版本。

**注意**  
必须确保满足所有 [先决条件](#mgdcomponent-distributor-prereq)，才能在配方中使用 `aws-vss-components-windows` 组件。

## 查找 Distributor 软件包
<a name="mgdcomponent-distributor-find-pkg"></a>

亚马逊和第三方提供公共软件包，您可以通过 Systems Manager Distributor 安装这些软件包。

要在中查看可用软件包 AWS 管理控制台，请登录[AWS Systems Manager 控制台](https://console.aws.amazon.com/systems-manager/;)并从导航窗格中选择 Dist **ri** butor。**Distributor** 页面显示可供您使用的所有软件包。有关使用列出可用软件包的更多信息 AWS CLI，请参阅《*AWS Systems Manager 用户指南》*中的[查看软件包（命令行）](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor-view-packages.html)。

您还可以创建自己的私有 Systems Manager Distributor 软件包。有关更多信息，请参阅 *《AWS Systems Manager 用户指南*》中的[创建软件包](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor-working-with-packages-create.html)。