AWS リソースが準拠していない場合に、カスタムメール通知を送信する Amazon EventBridge ルールを作成したいと考えています。
簡単な説明
NON_COMPLIANT となっている AWS Config 評価ルール出力を照合するには、最初に、カスタムイベントパターンと入力トランスフォーマーを含む EventBridge ルールを作成します。次に、EventBridge からの応答を Amazon Simple Notification Service (Amazon SNS) トピックにルーティングします。
解決策
次の例では、ec2-security-group-attached-to-eni マネージドルールが AWS リソースを NON_COMPLIANT と報告したときに、EventBridge によって Amazon SNS 通知が送信されます。非準拠リソースは Amazon Elastic Compute Cloud (Amazon EC2) セキュリティグループです。
注: resourceType フィールドと configRuleName フィールドは、使用する Config ルールの実際の値に置き換えることができます。
次の手順を実行します。
-
Amazon SNS トピックを作成します。既存の Amazon SNS トピックがある場合は、次のステップに進んでください。重要: Amazon SNS トピックは、AWS Config サービスと同じ AWS リージョンにある必要があります。
-
EventBridge コンソールを開きます。
-
[EventBridge Rule with event pattern] (イベントパターンを含む EventBridge ルール) を選択し、[Create rule] (ルールを作成) を選択します。
-
[Visual rule builder opt in] (ビジュアルルールビルダー オプトイン) を選択し、次の情報を入力します。[Name] (名前) に、ルールの名前を入力します。(オプション) [Description] (説明) に、ルールの説明を入力します。その後、[Next] (次へ) をクリックします。
-
[Event source] (イベントソース) で、[AWS events or EventBridge partner events] (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] (入力トランスフォーマーを設定) を選択します。[Target input transformer] (ターゲット入力トランスフォーマー) の [Input Path] (入力パス) テキストボックスに、次のパスの例を入力します。
{
"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 AWS Config rule evaluated the with Id in the account in the as.For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=<awsRegion>#/timeline/<resourceType>/<resourceId>/configuration"
-
[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 the 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 が新しいリソースを検出した際のカスタムメール通知を設定する方法を教えてください。
GuardDuty に対する EventBridge ルールを構成し、特定のサービス検出タイプに関するカスタム SNS 通知を送信する方法を教えてください。