跳至内容

如何对 Image Builder 中的构建管道超时错误进行故障排除?

3 分钟阅读
0

我想对 EC2 Image Builder 中收到的构建管道超时错误进行故障排除。

解决方法

**注意:**如果您在运行 AWS 命令行界面 (AWS CLI) 命令时收到错误,请参阅 AWS CLI 错误故障排除。此外,请确保您使用的是最新版本的 AWS CLI。

要对构建管道超时错误进行故障排除,请根据超时发生的时间执行以下操作。有关如何监控超时的信息,请参阅使用 Amazon CloudWatch Logs 监控 Image Builder 日志。

构建验证 SSM Agent 可用性时发生超时

如果在构建验证 AWS Systems Manager Agent (SSM Agent) 时发生超时,您可能会收到以下错误消息之一:

"Workflow Execution ID: failed with reason: ExpectationNotMet. ssm:*CommandInvocations returned terminal state Failed in workflow step LaunchBuildInstance."

"Workflow Execution ID: failed with reason: An error occurred (InvalidInstanceId) when calling the SendCommand operation: Instances [[i-1a1b1c1d1e1f1g1h1]] not in a valid state for account in workflow step LaunchBuildInstance."

"Workflow Execution ID: failed with reason: ExpectationNotMet. ec2:DescribeInstanceStatus did not meet terminal states: [['passed']] after 100 attempts.Reason: Timeout. in workflow step LaunchBuildInstance."

要对这些错误进行故障排除,请执行以下操作。

验证 Amazon EC2 实例是否具有所需的 IAM 权限

确保您的 Amazon Elastic Compute Cloud (Amazon EC2) 实例具有所需的 AWS Identity and Access Management (IAM) 权限。将 AmazonSSMManagedInstanceCore 托管策略附加到您为 Image Builder 使用的 IAM 角色。要确定您为 Image Builder 使用的角色,请查看基础架构配置详细信息。此外,请确保 AWSServiceRoleForImageBuilder 角色能够使用映像配方块设备上指定的 AWS Key Management Service (AWS KMS) 密钥。

确保 SSM Agent 可以连接到端点

根据您的配置检查以下设置:

  • 如果您使用带有互联网网关的公有子网,请将子网配置为自动分配公有 IPv4 地址。
  • 如果您使用带有 NAT 网关的私有子网,请将 NAT 网关配置为使用公有子网。
  • 如果您使用带有 Amazon Virtual Private Cloud (Amazon VPC) 端点的私有子网,请为 AWS Systems Manager 配置私有端点。
  • 确认安全组和网络访问控制列表允许临时端口 1024-65535 上的入站连接以及端口 443 上的出站连接。
  • 如果您使用带有 AWS PrivateLink 端点的私有子网,请确认 Amazon VPC 端点的安全组允许端口 443 上的入站连接。
    **注意:**要允许入站连接,请使用子网或 Amazon VPC CIDR 地址。

有关更多故障排除步骤,请参阅为什么我的映像构建管道在 Image Builder 中失败并显示 "Step timed out while step is verifying the Systems Manager Agent availability on the target instance(s)" 错误?

构建下载 AWS CLI 时发生超时

如果 EC2 实例的亚马逊及其映像 (AMI) 没有 AWS CLI,则引导脚本会通过互联网安装 AWS CLI。但是,如果您在不允许互联网连接的私有子网上进行构建,则会在 ApplyBuildComponents 步骤中发生构建超时。对于容器构建,会在 BootstrapBuildInstance 步骤中发生超时。

要解决此超时问题,请允许子网通过 NAT 网关或互联网网关进行互联网连接。或者,创建已安装 AWS CLI 的自定义 AMI。

在 LaunchBuildInstance 步骤中发生超时

您必须在构建实例中使用唯一的根设备名称。因此,将根设备命名为 /dev/xvda 或 /dev/sda1 并不是最佳做法。如果您在使用 CreateImageRecipe API 时使用了重复的根设备名称,则会收到超时并显示以下错误消息:

"Workflow Execution ID: failed with reason: ExpectationNotMet. ec2:DescribeInstanceStatus did not meet terminal states: [['passed']] after 100 attempts.Reason: Timeout. in workflow step LaunchBuildInstance."

**注意:**如果您使用基于 AWS Nitro System 构建的实例或 Xen 实例类型的实例,则可以使用重复的设备名称。

要检查源 AMI 的设备名称,请运行以下 describe-images AWS CLI 命令:

aws ec2 describe-images \
    --region exampleregion \
    --image-ids exampleami

**注意:**请将 exampleregion 替换为您的 AWS 区域,并将 exampleami 替换为源 AMI ID。

在输出中,检查 RootDeviceName 的值。确保在 Image Builder 配方中使用相同的设备名称。

构建获取 Image Builder 组件时发生超时

如果您在私有子网上进行构建,而 Image Builder 无法连接到下载组件,则会收到以下错误消息:

"failed with reason: failed to download the EC2 Image Builder Component, operation error imagebuilder: GetComponent, exceeded maximum number of attempts, 3, dial tcp i/o timeout."

要解决上述错误,请确保您的安全组和 DNS 解析允许在所需端口上进行通信。或者,为 Image Builder 基础架构配置中使用的相同 VPC 和子网创建接口 Amazon VPC 端点。此外,验证您的配置是否符合 Image Builder 要求。

构建检索映像列表时发生超时

Amazon Linux 将映像列表存储在 Amazon Simple Storage Service (Amazon S3) 存储桶中。如果您在无权访问 Amazon S3 的私有子网上构建,则会收到以下超时错误消息:

"Could not retrieve mirrorlist; error was 12: Timeout was reached."

要解决此问题,请为 Amazon S3 创建 Amazon VPC 网关端点。默认情况下,当您创建端点时,Amazon VPC 会将 Amazon S3 前缀列表添加到路由表中。但是,最佳做法是确认前缀列表位于路由表中。

如果您在非 Amazon Linux 的 AMI 上进行构建,则映像列表不会存储在 Amazon S3 上。在这种情况下,当构建获取存储库/映像列表时,可能会发生构建超时。请确保在网络防火墙或代理中允许放行存储库地址或 URL。如果存储库/映像列表需要连接互联网,则允许子网通过 NAT 网关连接互联网。

在 ApplyBuildComponents 步骤中发生超时

如果在 ApplyBuildComponents 步骤中发生构建超时,您会收到以下错误消息:

"Workflow Execution ID: failed with reason: ExpectationNotMet. ssm:ListCommandInvocations did not meet terminal states: [['Success']] after 1440 attempts.Reason: Timeout. in workflow step ApplyBuildComponents."

要对此问题进行故障排除,请分析 Image Builder 发送到基础设施的 Amazon S3 存储桶的日志。有关更多信息,请参阅对管道构建进行故障排除中的查看工作流运行时日志。

此外,分析用于构建或测试新映像的实例的组件日志。在检查日志之前,请停用 Terminate instance on failure(失败时终止实例)功能。要访问此功能,请完成以下步骤:

  1. 打开 Image Builder 控制台。
  2. 选择 Edit infrastructure(编辑基础架构)。
  3. 选择 Edit(编辑),然后选择 Specify settings to troubleshoot issues with building your image(指定设置以排查构建映像时出现的问题)。
  4. 选择 Instance settings(实例设置),然后清除 Terminate instance on failure(失败时终止实例)。

**注意:**detailedoutput.json 日志文件描述了组件失败或超时的原因。application.log 文件提供调试级别的故障排除信息。

最后,检查您的文档的 YAML 架构中的 timeoutSeconds 参数值。默认值为 7200。要延长 Image Builder 超时之前的时间,请更新 YAML 文档中的值。值 -1 表示无穷大。

AWS 官方已更新 10 个月前