Knowledge Center Monthly Newsletter - March 2025
Stay up to date with the latest from the Knowledge Center. See all new and updated Knowledge Center articles published in the last month and re:Post’s top contributors.
AWS 資源不符合規範時,如何使用 AWS Config 收到通知?
我想建立 Amazon EventBridge 規則,在 AWS 資源不符合規範時,會傳送自訂電子郵件通知給我。
簡短說明
若要將 AWS Config 評估規則輸出比對為 NON_COMPLIANT,請先建立具有自訂事件模式和輸入變壓器的 EventBridge 規則。然後,將來自 EventBridge 的回應路由至 Amazon Simple Notification Service (Amazon SNS) 主題。
解決方案
在下列範例中,當 ec2-security-group-attached-to-eni 受管理規則將 AWS 資源報告為 NON_COMPLIANT 時,系統會收到 SNS 通知。不合規資源是 Amazon Elastic Compute Cloud (Amazon EC2) 安全群組。
**注意事項:**您可以替換特定 AWS 服務和 AWS Config 規則的 AWS Config 資源類型和規則。
完成下列步驟:
-
建立 Amazon SNS 主題。如果您有現有的 Amazon SNS 主題,請繼續進行下一步。
**重要注意事項:**Amazon SNS 主題必須與您的 AWS Config 服務位於相同 AWS 區域。 -
開啟 EventBridge 主控台。
-
選取 EventBridge Rule (EventBridge 規則),然後選擇 Create rule (建立規則)。
-
在 Define rule detail (定義規則詳細資料) 畫面上的 Rule detail (規則詳細資料) 下方,輸入下列資訊:
對於 Name (名稱),輸入規則的名稱。
(選用) 對於 Description (描述),輸入規則的描述。
對於 Rule type (規則類型),選擇 Rule with an event pattern (具有事件模式的規則)。然後,選擇 Next (下一步)。 -
對於 Event source (事件來源),選擇 AWS 事件或 EventBridge 合作夥伴事件。
-
在 Creation method (建立方法) 下方,選擇 Custom pattern (JSON editor) (自訂模式 (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" ] } } }
-
選擇 Next (下一步)。
-
在 Select target(s) (選取目標) 畫面上,輸入下列資訊:
在 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.awsRegion", "resourceId": "$.detail.resourceId", "awsAccountId": "$.detail.awsAccountId", "compliance": "$.detail.newEvaluationResult.complianceType", "rule": "$.detail.configRuleName", "time": "$.detail.newEvaluationResult.resultRecordedTime", "resourceType": "$.detail.resourceType" }
在 Template (範本) 中,輸入下列範本範例:
"On yourTime AWS Config rule yourRule evaluated the yourResourceType with Id yourResourceId in the account yourAWSAccountId Region yourAwsRegion as yourCompliance. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=yourAwsRegion#/timeline/yourResourceType/yourResourceId]/configuration"
**注意事項:**在上述範例中,請根據您使用案例所需的時間、規則、資源類型、資源識別碼、AWS 帳戶識別碼和 AWS 區域、合規和資源資訊,以您自己的值取代 yourTime、yourRule、yourResourceType、yourResourceId、yourAWSAccountId、yourAWSRegion、 和 yourCompliance。
選擇 Confirm (確認)。 -
選擇 Next (下一步)。然後,選擇 Next (下一步)。
-
選擇 Create rule (建立規則)。
觸發事件類型後,您會收到內含已填入自訂欄位的 SNS 電子郵件通知。
範例:
"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"
相關資訊
如何在 Amazon Route 53 託管區域記錄變更時收到通知?
使用 AWS Config 服務在 AWS 帳戶中建立資源後,如何接收自訂電子郵件通知?
對於特定 AWS 服務事件類型,如何為 GuardDuty 設定 EventBridge 規則以傳送自訂 SNS 通知?

相關內容
- 已提問 5 個月前lg...
- 已提問 5 個月前lg...
- AWS 官方已更新 3 年前
- AWS 官方已更新 5 個月前
- AWS 官方已更新 4 年前
- AWS 官方已更新 1 年前