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

2 分钟阅读
0

我创建了一个 Amazon EventBridge 规则,用于在创建新的 AWS 资源时启动服务事件类型。但是,响应采用的是 JSON 格式。如何才能收到含有自定义通知的电子邮件响应?

解决方法

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

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

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

1.    如果您尚未创建 Amazon SNS 主题,请按照 Amazon SNS 入门中的说明创建一个。

**注:**Amazon SNS 主题必须与您的 AWS Config 服务位于同一区域。

2.    打开 EventBridge 控制台,然后从导航窗格中选择 Rules(规则)。

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

4.    对于 Name(名称),输入您的规则名称。可选择输入 Description(描述)。

5.    对于 Rule type(规则类型),选择 Rule with an event pattern(包含事件模式的规则),然后选择 Next(下一步)。

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

7.    在 Event pattern(事件模式)窗格中,选择 Custom patterns (JSON editor) [自定义模式(JSON 编辑器)],然后粘贴以下示例事件模式:

**注:**您可以使用其他资源替换 EC2::Instance 资源类型。如需可用资源类型列表,请参阅 ResourceIdentifier 中的 resourceType 部分。

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

8.    选择下一步

9.    对于 Target types(目标类型),选择 AWS service(AWS 服务)。

10.    对于 Select a target(选择目标),选择 SNS topic(SNS 主题)。

11.    对于 Topic(主题),选择您的 SNS 主题。

12.    展开 Additional settings(其他设置)。然后,对于 Configure target input(配置目标输入),选择 Input transformer(输入转换器)。

13.    选择 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"
}

14.    对于 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"

15.    选择 Confirm(确认)。然后,选择 Next(下一步)。

16.    或者,您可以 Add new tag(添加新标签)。然后,选择 Next(下一步)。

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

18.    事件类型启动后,您将收到一份 SNS 电子邮件通知,其中的自定义字段将从第 13 步填充,与以下所示类似:

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

相关信息

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

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

AWS 官方
AWS 官方已更新 2 年前