亚马逊在 Image Builder 中的 EventBridge 集成 - EC2 Image Builder
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

亚马逊在 Image Builder 中的 EventBridge 集成

Amazon EventBridge 是一项无服务器事件总线服务,您可以使用它来连接您的 Image Builder 应用程序与其他 Amazon Web Services应用程序的相关数据。在中 EventBridge,规则匹配传入的事件并将其发送到目标进行处理。一条规则可以将一个事件发送到多个目标,然后这些事件并行运行。

借 EventBridge助,您可以自动执行 Amazon Web Services 并自动响应系统事件,例如应用程序可用性问题或资源更改。来自 Amazon Web Services 的事件以近乎实时 EventBridge 的方式传送到。您可以设置对传入事件做出反应以启动操作的规则。例如,当 EC2 实例的状态从待处理变为正在运行时,向 Lambda 函数发送事件。这些被称为模式。要基于事件模式创建规则,请参阅 EventBridge 《亚马逊 EventBridge 用户指南》中的创建对事件做出反应的亚马逊规则。

可自动触发的操作包括:

  • 调用一个 Amazon Lambda 函数

  • 调用 Amazon EC2 Run Command

  • 将事件中继到 Amazon Kinesis Data Streams

  • 激活 Amazon Step Functions 状态机

  • 通知 Amazon SNS 主题或 Amazon SQS 队列

您还可以为默认事件总线设置调度规则,使其定期执行操作,例如运行 Image Builder 管道以每季度刷新一次映像。有两种类型的计划表达式:

  • cron 表达式 — 以下 cron 表达式示例将任务安排在每天中午 (UTC+0) 运行:

    cron(0 12 * * ? *)

    有关将 cron 表达式与配合使用的更多信息 EventBridge,请参阅 A mazon EventBridge 用户指南中的 Cron 表达式

  • rate 表达式 — 以下 rate 表达式示例将任务安排为每 12 小时运行一次:

    rate(12 hour)

    有关在中使用费率表达式的更多信息 EventBridge,请参阅 Amazon EventBridge 用户指南中的费率表达式

有关 EventBridge 规则如何与 Image Builder 图像管道集成的更多信息,请参阅在 Image Builder 管道中使用 EventBridge 规则

Image Builder 发送的事件消息

当 Image Builder 资源的状态发生重大变化 EventBridge 时,Image Builder 会向其发送事件消息。例如,当图像的状态发生变化时。以下示例显示了 Image Builder 可能发送的典型 JSON 事件消息。

EC2 Image Builder 映像状态更改

在图像创建过程中,当图像资源的状态发生变化时,Image Builder 会发送此事件。例如,当图像状态从一种状态变为另一种状态时,如下所示:

  • buildingtesting

  • testingdistribution

  • testingfailed

  • integratingavailable

{ "version": "0", "id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "detail-type": "EC2 Image Builder Image State Change", "source": "aws.imagebuilder", "account": "111122223333", "time": "2024-01-18T17:50:56Z", "region": "us-west-2", "resources": ["arn:aws:imagebuilder:us-west-2:111122223333:image/cmkencryptedworkflowtest-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222/1.0.0/1"], "detail": { "previous-state": { "status": "TESTING" }, "state": { "status": "AVAILABLE" } } }
检测到 EC2 Image Builder CVE

如果您为图像启用了 CVE 检测,则每当图像扫描完成时,Image Builder 都会发送一条包含结果的消息。

{ "version": "0", "id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "detail-type": "EC2 Image Builder CVE Detected", "source": "aws.imagebuilder", "account": "111122223333", "time": "2023-03-01T16:59:09Z", "region": "us-east-1", "resources": [ "arn:aws:imagebuilder:us-east-1:111122223333:image/test-image/1.0.0/1", "arn:aws:imagebuilder:us-east-1:111122223333:image-pipeline/test-pipeline" ], "detail": { "resource-id": "i-1234567890abcdef0", "finding-severity-counts": { "all": 0, "critical": 0, "high": 0, "medium": 0 } } }
EC2 Image Builder 工作流程步骤正在等待

WaitForAction工作流程步骤暂停以等待异步操作完成时,Image Builder 会发送一条消息。

{ "version": "0", "id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "detail-type": "EC2 Image Builder Workflow Step Waiting", "source": "aws.imagebuilder", "account": "111122223333", "time": "2024-01-18T16:54:44Z", "region": "us-west-2", "resources": ["arn:aws:imagebuilder:us-west-2:111122223333:image/workflowstepwaitforactionwithvalidsnstopictest-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222/1.0.0/1", "arn:aws:imagebuilder:us-west-2:111122223333:workflow/build/build-workflow-a1b2c3d4-5678-90ab-cdef-EXAMPLE33333/1.0.0/1"], "detail": { "workflow-execution-id": "wf-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "workflow-step-execution-id": "step-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "workflow-step-name": "TestAutoSNSStop" } }