使用 AWS Config 创建资源时,如何接收自定义电子邮件通知?

2 分钟阅读
0

我创建了 Amazon EventBridge 规则,以便在 AWS Config 创建新的 AWS 资源时针对服务事件类型启动。但是,响应采用 JSON 格式。

解决方法

使用带有 EventBridge 规则的自定义事件模式来匹配 AWS Config 支持的资源类型。然后,将响应路由到 Amazon Simple Notification Service (Amazon SNS) 主题。

在以下示例中,当使用 AWS::EC2::Instance 资源类型创建新的 Amazon Elastic Compute Cloud (Amazon EC2) 实例时,您将收到 SNS 通知。

**注意:**将资源类型替换为您的特定 AWS 服务。

完成以下步骤:

  1. 创建 Amazon SNS 主题
    **注意:**Amazon SNS 主题必须与 AWS Config 服务位于同一 AWS 区域。

  2. 打开 EventBridge 控制台

  3. 在导航窗格中,选择 Rules(规则),然后选择 Create rule(创建规则)。

  4. 输入以下信息:
    对于 Name(名称),输入规则的名称。
    (可选)对于 Description(描述),输入规则的描述。
    对于 Rule type(规则类型),选择 Rule with an event pattern(具有事件模式的规则),然后选择 Next(下一步)。
    对于 Event source(事件来源),选择 AWS events or EventBridge partner events(AWS 事件或 EventBridge 合作伙伴事件)。

  5. Event pattern(事件模式)下,选择 Custom patterns (JSON editor)(自定义模式(JSON 编辑器))。然后,输入以下示例事件模式:

    {
      "source": [
        "aws.config"
      ],
      "detail-type": [
        "Config Configuration Item Change"
      ],
      "detail": {
        "messageType": [
          "ConfigurationItemChangeNotification"
        ],
        "configurationItem": {
          "resourceType": [
            "AWS::EC2::Instance"
          ],
          "configurationItemStatus": [
            "ResourceDiscovered"
          ]
        }
      }
    }

    **注意:**将 EC2::Instance 资源类型替换为您的资源类型。有关可用资源类型的列表,请参阅 ResourceIdentifier 中的 resourceType 部分。

  6. 选择 Next(下一步)。

  7. 输入以下信息:
    对于 Target types(目标类型),选择 AWS service(AWS 服务)。
    对于 Select a target(选择目标),选择 SNS topic(SNS 主题)。
    对于 Topic(主题),选择您的 SNS 主题。
    Additional settings(其他设置)下,对于 Configure target input(配置目标输入),选择 Input transformer(输入转换器)。

  8. 选择 Configure input transformer(配置输入转换器)。然后,在 Input Path(输入路径)文本框的 Target input transformer(目标输入转换器)下,输入以下示例路径:

    {
        "awsRegion": "$.detail.configurationItem.awsRegion",
        "awsAccountId": "$.detail.configurationItem.awsAccountId",
        "resource_type": "$.detail.configurationItem.resourceType",
        "resource_ID": "$.detail.configurationItem.resourceId",
        "configurationItemCaptureTime": "$.detail.configurationItem.configurationItemCaptureTime"
    }
  9. 对于 Template(模板)文本框,输入以下示例模板:

    "On <configurationItemCaptureTime> AWS Config service recorded a creation of a new <resource_type> with Id <resource_ID> in the account <awsAccountId> region <awsRegion>. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=<awsRegion>#/timeline/<resource_type>/<resource_ID>/configuration"
  10. 选择 Confirm(确认)。然后,选择 Next(下一步)。

  11. 选择 Create rule(创建规则)。

如果启动了某个事件类型,则将收到一封 SNS 电子邮件通知,其中包含填充的自定义字段。

示例:

"On ExampleTime AWS Config service recorded a creation of a new AWS::EC2::Instance with Id ExampleID in the account AccountID region ExampleRegion. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=*ExampleRegion*#/timeline/AWS::EC2::Instance/*ExampleID*/configuration"

相关信息

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

使用 AWS Config 服务在我的 AWS 账户中删除资源时,如何接收自定义电子邮件通知?

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