使用 AWS Config 服務刪除 AWS 帳戶中的資源時,如何接收自訂電子郵件通知?

2 分的閱讀內容
0

我建立了 Amazon EventBridge 規則,用於在刪除 AWS 資源時啟動服務事件類型。但回應卻是以 JSON 格式來呈現。如何才能收到包含自訂通知的電子郵件回應?

解決方法

您可以使用具備 EventBridge 規則的自訂事件模式比對 AWS Config 支援的資源類型。然後,將回應路由至 Amazon Simple Notification Service (Amazon SNS) 主題。

在下列範例中,當終止 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體時,會收到 SNS 通知。

**注意:**您可以為特定 AWS 服務替換資源類型。

  1. 如果您尚未建立 Amazon SNS 主題,請依照 Amazon SNS 入門的指示進行操作。

**注意:**Amazon SNS 主題必須與您的 AWS Config 服務位於相同區域。

  1. 開啟 EventBridge 主控台,然後從導覽窗格中選擇規則

  2. 選擇建立規則

4.    在名稱中,輸入您的規則名稱。

  1. 定義模式中,選擇事件模式

  2. 事件相符模式中,選擇自訂模式

  3. 事件模式預覽窗格中,輸入以下範例事件模式**:**

{
  "source": [
    "aws.config"
  ],
  "detail-type": [
    "Config Configuration Item Change"
  ],
  "detail": {
    "messageType": [
      "ConfigurationItemChangeNotification"
    ],
    "configurationItem": {
      "configurationItemStatus": [
        "ResourceDeleted"
      ]
    }
  }
}
  1. 對於目標,選擇 SNS 主題

  2. 對於主題,選擇您的 SNS 主題。

  3. 展開設定輸入,然後選擇輸入轉換器

  4. 輸入路徑文字方塊中,輸入下列範例路徑:

{
    "awsRegion": "$.detail.configurationItem.awsRegion",
    "awsAccountId": "$.detail.configurationItem.awsAccountId",
    "resource_type": "$.detail.configurationItem.resourceType",
    "resource_ID": "$.detail.configurationItem.resourceId",
    "configurationItemCaptureTime": "$.detail.configurationItem.configurationItemCaptureTime"
}
  1. 輸入範本文字方塊中,輸入下列範例範本:
"On <configurationItemCaptureTime> AWS Config service recorded a deletion of the resource <resource_ID> type <resource_type> 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"

13.    選擇建立

  1. 如果已啟動事件類型,您會收到 SNS 電子郵件通知,其中包含步驟 12 填入的自訂欄位,如下所示:
"On ExampleTime AWS Config service recorded a deletion of the resource ExampleID type
 ExampleResourceType in the account ExampleAccountID region ExampleRegion. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=*ExampleRegion*#/timeline/*ExampleResourceType*/*ExampleID*/configuration"

相關資訊

使用 AWS Config 服務在 AWS 帳戶中建立資源後,如何接收自訂電子郵件通知?

如果特定 AWS 服務事件類型觸發,如何為 GuardDuty 設定 EventBridge 規則以傳送自訂 SNS 通知?

AWS 官方
AWS 官方已更新 3 年前