我建立了 Amazon EventBridge 規則,用於在建立新 AWS 資源時啟動服務事件類型。但回應卻是以 JSON 格式來呈現。如何才能收到包含自訂通知的電子郵件回應?
解決方法
您可以使用具備 EventBridge 規則的自訂事件模式比對 AWS Config 支援的資源類型。然後,將回應路由至 Amazon Simple Notification Service (Amazon SNS) 主題。
在下列範例中,當使用 AWS::EC2::Instance 資源類型建立新的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體時,會收到 SNS 通知。
**注意:**您可以為特定 AWS 服務替換資源類型。
- 如果您尚未建立 Amazon SNS 主題,請依照 Amazon SNS 入門的指示進行操作。
**注意:**Amazon SNS 主題必須與您的 AWS Config 服務位於相同區域。
-
開啟 EventBridge 主控台,然後從導覽窗格中選擇規則。
-
選擇建立規則。
4. 在名稱中,輸入您的規則名稱。您可以選擇輸入描述。
-
對於規則類型,選擇具有事件模式的規則,然後選擇下一步。
-
對於事件來源,選擇 AWS 事件或 EventBridge 合作夥伴事件。
-
在事件模式窗格中,選擇自訂模式 (JSON 編輯器),然後貼上下列範例事件模式:
注意: 您可以使用其他資源取代 EC2::Instance。如需可用資源類型的清單,請參閱 ResourceIdentifier 中的 resourceType 一節。
{
"source": [
"aws.config"
],
"detail-type": [
"Config Configuration Item Change"
],
"detail": {
"messageType": [
"ConfigurationItemChangeNotification"
],
"configurationItem": {
"resourceType": [
"AWS::EC2::Instance"
],
"configurationItemStatus": [
"ResourceDiscovered"
]
}
}
}
8. 選擇下一步。
-
對於目標類型,選取 AWS 服務。
-
對於選取目標,選擇 SNS 主題。
-
對於主題,選擇您的 SNS 主題。
-
展開其他設定。然後,在設定目標輸入中,選擇輸入轉換器。
-
選擇設定輸入轉換器。然後,在輸入路徑文字方塊的目標輸入轉換器下,輸入下列範例路徑:
{
"awsRegion": "$.detail.configurationItem.awsRegion",
"awsAccountId": "$.detail.configurationItem.awsAccountId",
"resource_type": "$.detail.configurationItem.resourceType",
"resource_ID": "$.detail.configurationItem.resourceId",
"configurationItemCaptureTime": "$.detail.configurationItem.configurationItemCaptureTime"
}
- 在範本文字方塊中,輸入下列範例範本:
"On <configurationItemCaptureTime> AWS Config service recorded a creation of a new <resource_type> with Id <resource_ID> in the account <awsAccountId> region <awsRegion>. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=<awsRegion>#/timeline/<resource_type>/<resource_ID>/configuration"
-
選擇確認。然後,選擇下一步。
-
或者,您可以新增標籤。然後,選擇下一步。
-
選擇建立規則。
-
如果已啟動事件類型,您會收到 SNS 電子郵件通知,其中包含步驟 13 填入的自訂欄位,如下所示:
"On ExampleTime AWS Config service recorded a creation of a new AWS::EC2::Instance with Id ExampleID in the account AccountID region ExampleRegion. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=*ExampleRegion*#/timeline/AWS::EC2::Instance/*ExampleID*/configuration"
相關資訊
如果特定 AWS 服務事件類型觸發,如何為 GuardDuty 設定 EventBridge 規則以傳送自訂 SNS 通知?
使用 AWS Config 服務刪除 AWS 帳戶中的資源時,如何接收自訂電子郵件通知?