我建立了 Amazon EventBridge 規則,用於在 AWS Config 建立新 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 主題必須與您的 AWS Config 服務位於相同 AWS 區域。
-
開啟 EventBridge 主控台。
-
在導覽窗格中,選擇 Rules (規則),然後選擇 Create rule (建立規則)。
-
輸入下列資訊:
對於 Name (名稱),輸入規則的名稱。
(選用) 對於 Description (描述),請輸入規則的描述。
對於 Rule type (規則類型),選擇 Rule with an event pattern (具有事件模式的規則),然後選擇 Next (下一步)。
對於 Event source (事件來源),選擇 AWS 事件或 EventBridge 合作夥伴事件。
-
對於 Event pattern (事件模式),選擇 Custom patterns (JSON editor) (自訂模式 (JSON 編輯器))。然後,輸入下列事件模式範例:
{
"source": [
"aws.config"
],
"detail-type": [
"Config Configuration Item Change"
],
"detail": {
"messageType": [
"ConfigurationItemChangeNotification"
],
"configurationItem": {
"resourceType": [
"AWS::EC2::Instance"
],
"configurationItemStatus": [
"ResourceDiscovered"
]
}
}
}
**注意事項:**請將 EC2::Instance 資源類型取代為您的資源類型。如需可用資源類型的清單,請參閱 ResourceIdentifier 中的 resourceType 一節。
-
選擇 Next (下一步)。
-
輸入下列資訊:
對於 Target types (目標類型),選取 AWS service (AWS 服務)。
對於 Select a target (選取目標),選擇 SNS topic (SNS 主題)。
對於 Topic (主題),選擇您的 SNS 主題。
在 Additional settings (其他設定) 下方,對於 Configure target input (設定目標輸入) 選擇 Input transformer (輸入變壓器)。
-
選擇 Configure input transformer (設定輸入變壓器)。然後,在 Input Path (輸入路徑) 文字方塊的 Target input transformer (目標輸入變壓器) 下方,輸入下列範例路徑:
{
"awsRegion": "$.detail.configurationItem.awsRegion",
"awsAccountId": "$.detail.configurationItem.awsAccountId",
"resource_type": "$.detail.configurationItem.resourceType",
"resource_ID": "$.detail.configurationItem.resourceId",
"configurationItemCaptureTime": "$.detail.configurationItem.configurationItemCaptureTime"
}
-
對於 Template (範本) 文字方塊,輸入下列範例範本:
"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"
-
選擇 Confirm (確認)。然後,選擇 Next (下一步)。
-
選擇 Create rule (建立規則)。
如果事件類型已啟動,您會收到 SNS 電子郵件通知,其中包含填入的自訂欄位。
範例:
"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 帳戶中的資源時,如何接收自訂電子郵件通知?