如何使用 AWS Config 在 AWS 资源不合规时接收通知?

2 分钟阅读
0

我想创建 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 规则。

完成以下步骤:

  1. 创建 Amazon SNS 主题。如果您已有 Amazon SNS 主题,请继续执行下一步。
    **重要事项:**Amazon SNS 主题必须与 AWS Config 服务位于同一 AWS 区域。

  2. 打开 EventBridge 控制台

  3. 选择 EventBridge Rule(EventBridge 规则),然后选择 Create rule(创建规则)。

  4. Define rule detail(定义规则详细信息)屏幕上的 Rule detail(规则详细信息)下,输入以下信息:
    对于 Name(名称),输入规则的名称。
    (可选)对于 Description(描述),输入规则的描述。
    对于 Rule type(规则类型),选择 Rule with an event pattern(具有事件模式的规则)。然后,选择 Next(下一步)。

  5. 对于 Event source(事件来源),选择 AWS events or EventBridge partner events(AWS 事件或 EventBridge 合作伙伴事件)。

  6. 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"
          ]
        }
      }
    }
  7. 选择 Next(下一步)。

  8. 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 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"

    **注意:**在前面的示例中,根据用例的要求,将 yourTime、yourRule、yourResourceType、yourResourceId、yourAWSAccountId、yourAWSRegionyourCompliance 替换为您自己的时间、规则、资源类型、资源 ID、AWS 账户 ID 和 AWS 区域、合规性和资源信息。
    选择 Confirm(确认)。

  9. 选择 Next(下一步)。然后,选择 Next(下一步)。

  10. 选择 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 账户中创建资源时,如何接收自定义电子邮件通知?

如何为 GuardDuty 配置 EventBridge 规则,以便发送针对特定 AWS 服务事件类型的自定义 SNS 通知?

AWS 官方
AWS 官方已更新 4 个月前