

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Image Builder 中的 Amazon EventBridge 整合
<a name="integ-eventbridge"></a>

Amazon EventBridge 是一種無伺服器事件匯流排服務，可用來將 Image Builder 應用程式與其他相關資料連線 AWS 服務。在 EventBridge 中，規則符合傳入事件，並將其傳送至目標進行處理。單一規則可以將事件傳送至多個目標，然後這些事件會平行執行。

使用 EventBridge，您可以自動化您的 AWS 服務 ，並自動回應系統事件，例如應用程式可用性問題或資源變更。 AWS 服務 的事件會以接近即時的方式傳送到 EventBridge。您可以設定對傳入事件做出反應的規則，以啟動動作。例如，當 EC2 執行個體的狀態從待定變更為執行中時，將事件傳送至 Lambda 函數。這些稱為*模式*。若要根據事件模式建立規則，請參閱《[Amazon EventBridge 使用者指南》中的建立對事件做出反應的](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule.html) *Amazon EventBridge *規則。

可自動啟動的動作包括下列項目：
+ 叫用 AWS Lambda 函數
+ 叫用 Amazon EC2 執行命令
+ 將事件轉送至 Amazon Kinesis Data Streams
+ 啟用 AWS Step Functions 狀態機器
+ 通知 Amazon SNS 主題或 Amazon SQS 佇列

您也可以設定預設事件匯流排的排程規則，以定期執行動作，例如執行映像建置器管道以每季重新整理映像。排程表達式有兩種類型：
+ **cron 表達**式 – 下列 cron 表達式範例會將任務排程為每天中午 UTC\$10 執行：

  `cron(0 12 * * ? *)`

  如需搭配 EventBridge 使用 Cron 表達式的詳細資訊，請參閱《*Amazon EventBridge 使用者指南*》中的 [Cron 表達](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-cron-expressions)式。
+ **速率表達式** – 下列速率表達式範例會排程任務每 12 小時執行一次：

  `rate(12 hour)`

  如需搭配 EventBridge 使用速率表達式的詳細資訊，請參閱《*Amazon EventBridge 使用者指南*》中的[速率表達](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-rate-expressions)式。

如需 EventBridge 規則如何與映像建置器映像管道整合的詳細資訊，請參閱[搭配映像建置器管道使用 EventBridge 規則](ev-rules-for-pipeline.md)。

## Image Builder 傳送的事件訊息
<a name="integ-eb-event-summary"></a>

當 Image Builder 資源的狀態發生重大變更時，Image Builder 會將事件訊息傳送至 EventBridge。例如，當映像的狀態變更時。下列範例顯示 Image Builder 可能傳送的典型 JSON 事件訊息。

**Topics**
+ [EC2 映像建置器映像狀態變更](#eb-event-state-change)
+ [偵測到 EC2 Image Builder CVE](#eb-event-cve-detected)
+ [EC2 映像建置器工作流程步驟等待中](#eb-event-wf-step-waiting)
+ [EC2 映像建置器映像管道自動停用](#eb-event-pipeline-disabled)

### EC2 映像建置器映像狀態變更
<a name="eb-event-state-change"></a>

映像建置器會在映像建立期間變更映像資源的狀態時傳送此事件。例如，當影像狀態從一個狀態變更為另一個狀態時，如下所示：
+ 從 `building` 到 `testing`
+ 從 `testing` 到 `distribution`
+ 從 `testing` 到 `failed`
+ 從 `integrating` 到 `available`

```
{
    "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
<a name="eb-event-cve-detected"></a>

如果您已啟用映像的 CVE 偵測，映像建置器會在映像掃描完成時傳送包含結果的訊息。

```
{
    "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 映像建置器工作流程步驟等待中
<a name="eb-event-wf-step-waiting"></a>

當`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"
    }
}
```

### EC2 映像建置器映像管道自動停用
<a name="eb-event-pipeline-disabled"></a>

如果您已`autoDisablePolicy`為管道設定 ，則 Image Builder 會停用管道，並在連續排程管道執行失敗次數超過政策允許的數目上限時，將事件訊息傳送至 EventBridge。

```
{
    "version": "0",
    "id": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
    "detail-type": "EC2 Image Builder Image Pipeline Automatically Disabled",
    "source": "aws.imagebuilder",
    "account": "111122223333",
    "time": "2025-09-18T16:54:44Z",
    "region": "us-west-2",
    "resources": ["arn:aws:imagebuilder:us-west-2:111122223333:image-pipeline/disabled-image-pipeline-name"],
    "detail": {
        "consecutive-failures": "5"
    }
}
```