AWS リソースが準拠していない場合に AWS Config を使用して通知を受けるにはどうすればよいですか?
最終更新日: 2020 年 4 月 27 日
AWS リソースが準拠していない場合に通知をトリガーする Amazon EventBridge ルールを作成しましたが、レスポンスが JSON 形式です。カスタマイズされた通知を E メールで受信するにはどうすればよいですか?
簡単な説明
EventBridge ルール をカスタムイベントパターンと入力トランスフォーマーとともに使用して、AWS Config 評価ルール出力を NON_COMPLIANT と照合します。次に、レスポンスを Amazon Simple Notification Service (Amazon SNS) トピックにルーティングします。
解決方法
次の例では、ec2-security-group-attached-to-eni のマネージドルールが Amazon Elastic Compute Cloud (Amazon EC2) のセキュリティグループに対し、NON_COMPLIANT として AWS をレポートすると、SNS 通知が届きます。
注意 : AWS Config リソースタイプとルールを、特定の AWS サービスと AWS Config ルールに置き換えることができます。
1. Amazon SNS トピックをまだ作成していない場合は、Amazon SNS の開始方法をご参照ください。
重要: Amazon SNS トピックは、AWS Config サービスと同じリージョンにある必要があります。
2. EventBridge コンソールを開きます。
3. [Create rule] (ルールの作成) を選択します。
4. [名前] に、ルール名を入力します。
5. [パターンの定義] で [イベントパターン] を選択します。
6. [イベント照会パターン] で [カスタムパターン] を選択します。
7. [イベントパターン] プレビューペインで、次のイベントパターンの例をコピーして貼り付けます。
{
"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. [保存] を選択します。
9. [ターゲットの選択] で [SNS トピック] を選択します。
10. [トピック] で、ご自身の SNS トピックを選択します。
11. [入力を設定] を展開し、[トランスフォーマーを入力] をクリックします。
12. [入力パス] テキストボックスに、次のサンプルパスをコピーして貼り付けます。
{
"awsRegion": "$.detail.awsRegion",
"resourceId": "$.detail.resourceId",
"awsAccountId": "$.detail.awsAccountId",
"compliance": "$.detail.newEvaluationResult.complianceType",
"rule": "$.detail.configRuleName",
"time": "$.detail.newEvaluationResult.resultRecordedTime",
"resourceType": "$.detail.resourceType"
}
13. [入力テンプレート] テキストボックスに、次のテンプレートをコピーして貼り付けます。
"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"
14. [作成] をクリックします。
15. イベントタイプがトリガーされた場合、次のようなステップ 13 で作成したカスタムフィールドを含む 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"