跳至內容

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

2 分的閱讀內容
0

我想使用 AWS Config,在 AWS 資源刪除時接收與服務事件類型相關的電子郵件通知。

解決方法

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

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

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

請完成下列步驟:

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

  2. 開啟 EventBridge console (EventBridge 主控台)。

  3. 在導覽窗格的 Rules (規則) 下,選擇 Rules (規則),然後選擇 Create rule (建立規則)。

  4. Define rule detail (定義規則詳細資料) 頁面上,輸入以下資訊:
    對於 Name (名稱),輸入規則的名稱。
    Rule type (規則類型) 中,選擇 Rule with an event pattern (具有事件模式的規則)。

  5. 選擇 Next (下一步)。

  6. Event source (事件來源) 中,選擇 AWS events or EventBridge partner events (AWS 事件或 EventBridge 合作夥伴事件)。
    Event pattern (事件模式) 中,選擇 Custom pattern (JSON editor) (自訂模式 (JSON 編輯器))。
    Event pattern (事件模式) 預覽窗格中,輸入下列範例事件模式:

    {
      "source": [
        "aws.config"
      ],
      "detail-type": [
        "Config Configuration Item Change"
      ],
      "detail": {
        "messageType": [
          "ConfigurationItemChangeNotification"
        ],
        "configurationItem": {
          "configurationItemStatus": [
            "ResourceDeleted"
          ]
        }
      }
    }
  7. 選擇 Next (下一步)。

  8. 目標 1 中,選擇 AWS service (AWS 服務)。

  9. Select a target (選取目標) 中,選擇 SNS topic (SNS 主題)。

  10. Target location (目標位置) 中,選擇 Target in this account (在此帳戶中定位)。

  11. Topic (主題) 中,選擇您的 Amazon SNS 主題。

  12. Additional settings (其他設定) 下,於 Configure target input (設定目標輸入) 中選擇 Input transformer (輸入轉換器)。然後,選擇 Configure input transformer (設定輸入轉換器)。

  13. Input path (輸入路徑) 中,輸入下列範例路徑:

{
    "awsRegion": "$.detail.configurationItem.awsRegion",
    "awsAccountId": "$.detail.configurationItem.awsAccountId",
    "resource_type": "$.detail.configurationItem.resourceType",
    "resource_ID": "$.detail.configurationItem.resourceId",
    "configurationItemCaptureTime": "$.detail.configurationItem.configurationItemCaptureTime"
}
  1. Template (範本) 中,輸入下列範例範本:
    「在 <configurationItemCaptureTime> AWS Config 服務記錄了帳戶中資源 <resource_ID> 類型 <resource_type> 的刪除 <awsAccountId> 區域 <awsRegion>。如需詳細資訊,請在 https://console.aws.amazon.com/config/home?region=#/timeline///configuration 打開 AWS Config 主控台」
  2. 選擇 Confirm (確認)。
  3. 選擇 Next (下一步)。
  4. 選擇 Next (下一步)。
  5. 選擇 Create rule (建立規則)。

相關資訊

使用 AWS Config 建立資源時,如何接收自訂電子郵件通知?

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

AWS 官方已更新 6 個月前