當使用 AWS Config 的 AWS 資源不合規時,會如何通知我?

2 分的閱讀內容
0

我建立了一個 Amazon EventBridge 規則,以便在 AWS 資源不合規時觸發通知,但回應是採用 JSON 格式。如何接收包含自訂通知的電子郵件?

簡短描述

使用具備自訂事件模式和輸入轉換器的 EventBridge 規則,以符合顯示為 NON_COMPLIANT 的 AWS Config 評估規則輸出。然後,將回應路由至 Amazon Simple Notification Service (Amazon SNS) 主題。

解決方法

在下列範例中,當 ec2-security-group-attached-to-eni 受管規則將 Amazon Elastic Compute Cloud (Amazon EC2) 安全群組的 AWS 資源報告為 NON_COMPLIANT 時收到 SNS 通知。

**注意:**您可以替換特定 AWS 服務和 AWS Config 規則的 AWS Config 資源類型規則

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

**重要事項:**Amazon SNS 主題必須與您的 AWS Config 服務位於相同區域。

  1. 開啟 EventBridge 主控台

  2. 選擇建立規則

  3. 名稱中,輸入您的規則名稱。如有需要,請輸入描述

  4. 對於規則類型,選擇具有事件模式的規則。然後,選擇下一步

  5. 對於事件來源,選擇 AWS 事件或 EventBridge 合作夥伴事件

  6. 事件模式窗格中,選擇自訂模式 (JSON 編輯器),然後複製並貼上下列範例事件模式:

{
  "source": [
    "aws.config"
  ],
  "detail-type": [
    "Config Rules Compliance Change"
  ],
  "detail": {
    "messageType": [
      "ComplianceChangeNotification"
    ],
    "configRuleName": [
      "ec2-security-group-attached-to-eni"
    ],
    "resourceType": [
      "AWS::EC2::SecurityGroup"
    ],
    "newEvaluationResult": {
      "complianceType": [
        "NON_COMPLIANT"
      ]
    }
  }
}

8.    選擇下一步

  1. 對於目標類型,選取 AWS 服務

  2. 對於選取目標,選擇 SNS 主題

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

  4. 展開其他設定。然後,在設定目標輸入中,選擇輸入轉換器

  5. 選擇設定輸入轉換器。在輸入路徑文字方塊的目標輸入轉換器下,複製並貼上下列範例路徑:

{
  "awsRegion": "$.detail.awsRegion",
  "resourceId": "$.detail.resourceId",
  "awsAccountId": "$.detail.awsAccountId",
  "compliance": "$.detail.newEvaluationResult.complianceType",
  "rule": "$.detail.configRuleName",
  "time": "$.detail.newEvaluationResult.resultRecordedTime",
  "resourceType": "$.detail.resourceType"
}
  1. 範本文字方塊中,複製並貼上下列範例。根據使用案例所需,輸入時間規則資源類型、資源 ID、AWS 帳戶 ID 和 AWS 區域、合規以及資源資訊。
"On <time> AWS Config rule <rule> evaluated the <resourceType> with Id <resourceId> in the account <awsAccountId> region <awsRegion> as <compliance> For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=<awsRegion>#/timeline/<resourceType>/<resourceId>/configuration"
  1. 選擇確認。然後,選擇下一步

  2. 或者,您可以新增標籤。然後,選擇下一步

  3. 選擇建立規則

  4. 觸發事件類型後,您會收到 SNS 電子郵件通知,其中包含步驟 13 填入的自訂欄位,如下所示:

"On ExampleTime AWS Config rule ExampleRuleName evaluated the ExampleResourceType with Id ExampleResource_ID in the account ExampleAccount_Id in Region ExampleRegion as ExamplecomplianceType. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=ExampleRegion#/timeline/ExampleResourceType/ExampleResource_ID/configuration"

相關資訊

對 Route 53 託管區域記錄進行變更時,會如何通知我?

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

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

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