View a markdown version of this page

更新基础设施配置 - EC2 Image Builder
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)。

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

更新基础设施配置

本节介绍如何更新基础架构配置资源。您可以使用映像生成器控制台, imagebuilder 中的命令 Amazon CLI,或 Amazon Tools for PowerShell。要跟踪资源,可以应用标签,如下所示。以键值对的形式输入标签。

  • 资源标签将元数据标签分配给 Image Builder 在构建过程中启动的 Amazon EC2 实例。

  • 标签将元数据标签分配给 Image Builder 作为输出创建的基础设施配置资源。

注意

我们建议,将 Image Builder 从管道版本中启动的所有 EC2 实例配置为使用 Imdsv2,这样实例元数据检索请求将需要签名令牌标头。

Console

您可以从 Image Builder 控制台编辑以下基础设施配置详细信息:

  • 基础设施配置的描述。

  • 将 IAM 角色 与实例配置文件关联。

  • Amazon 基础设施,包括 实例类型 还有一个 SNS 话题 用于通知。

  • VPC、子网和安全组。

  • 故障排除设置,包括失败时终止实例、用于连接的密钥对以及用于存储实例日志的可选 S3 存储桶位置。

提示

现在你可以使用 AI 进行创作。有关更多信息,请参阅 使用 AI 创建和更新资源-预览。

要通过 Image Builder 控制台更新基础设施配置资源,请执行以下步骤:

配置选择现有的 Image Builder 基础设施配置
  1. 打开 EC2 映像生成器控制台,网址为 https://console.aws.amazon.com/imagebuilder/。

  2. 要查看您账户下的基础设施配置资源列表,请从导航窗格中选择基础设施配置。

  3. 要查看详细信息或编辑基础设施配置,请选择配置名称链接。此操作将打开基础设施配置的详细视图。

    注意

    您也可以选中配置名称旁边的框,然后选择查看详细信息。

  4. 在基础设施详细信息面板的右上角,选择编辑。

  5. 准备保存对基础设施配置所做的更新时,请选择保存更改。

Amazon CLI

以下示例显示如何使用映像生成器更新映像的基础架构配置 更新基础架构配置 命令在 Amazon CLI。

  1. 创建 CLI 输入 JSON 文件

    此示例基于中的第一个示例 创建基础设施配置。它设定了 terminateInstanceOnFailure 到 true,因此,当构建失败时,使用此基础架构配置的管道会终止构建和测试实例。

    以下示例设置了常见的基础设施字段。要在构建和测试实例上要求 IMDSv2 令牌,请添加 instanceMetadataOptions 用方块阻止 httpTokens 设置为 required。

    使用文件编辑工具创建一个 JSON 文件,其中包含以下示例中显示的密钥,以及对您的环境有效的值。此示例使用名为 update-infrastructure-configuration.json 的文件:

    { "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure-configuration", "description": "An example that will terminate instances of failed builds", "instanceTypes": [ "m7i.large", "m7i.2xlarge" ], "instanceProfileName": "my-iam-instance-profile-name", "securityGroupIds": [ "sg-12345678" ], "subnetId": "subnet-12345678", "logging": { "s3Logs": { "s3BucketName": "amzn-s3-demo-logging-bucket", "s3KeyPrefix": "my-path" } }, "terminateInstanceOnFailure": true, "snsTopicArn": "arn:aws:sns:us-west-2:111122223333:my-topic" }
  2. 当您运行以下命令时,使用您作为输入而创建的文件。
    aws imagebuilder update-infrastructure-configuration --cli-input-json file://update-infrastructure-configuration.json
PowerShell

以下示例显示了如何使用 Update-EC2IBInfrastructureConfiguration cmdlet 用于更新基础架构配置。此示例基于中的第一个示例 创建基础设施配置。它设置了 TerminateInstanceOnFailure 参数为 $true,因此,当构建失败时,使用此基础架构配置的管道会终止构建和测试实例。

以下示例设置了常见的基础设施字段。要要求在构建和测试实例上使用 IMDSv2 令牌,请设置 InstanceMetadataOptions_HttpToken 参数为 required。

要更新基础架构配置,请运行 Update-EC2IBInfrastructureConfiguration cmdlet:

Update-EC2IBInfrastructureConfiguration -InfrastructureConfigurationArn arn:aws:imagebuilder:us-west-2:111122223333:infrastructure-configuration/my-example-infrastructure-configuration ` -Description "An example that will terminate instances of failed builds" ` -InstanceType m7i.large, m7i.2xlarge ` -InstanceProfileName my-iam-instance-profile-name ` -SecurityGroupId sg-12345678 ` -SubnetId subnet-12345678 ` -S3Logs_S3BucketName amzn-s3-demo-logging-bucket ` -S3Logs_S3KeyPrefix my-path ` -TerminateInstanceOnFailure $true ` -SnsTopicArn arn:aws:sns:us-west-2:111122223333:my-topic