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

2 分钟阅读
0

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

解决方法

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

在以下示例中,当 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(名称),输入您的规则名称。

5.    对于 Define pattern(定义模式),选择 Event Pattern(事件模式)。

6.    对于 Event matching pattern(事件匹配模式),选择 Custom pattern(自定义模式)

7.    在Event patter(事件模式)预览窗格中,输入以下示例事件模式**:**

{
  "source": [
    "aws.config"
  ],
  "detail-type": [
    "Config Configuration Item Change"
  ],
  "detail": {
    "messageType": [
      "ConfigurationItemChangeNotification"
    ],
    "configurationItem": {
      "configurationItemStatus": [
        "ResourceDeleted"
      ]
    }
  }
}

8.    对于Target(目标),请选择 SNS 主题

9.    在Topic(主题)中,选择您的 SNS 主题。

10.    展开Configure input(配置输入),然后选择 Input transformer(输入转换器)。

11.    在 Input Path(输入路径)文本框中,输入以下示例路径:

{
    "awsRegion": "$.detail.configurationItem.awsRegion",
    "awsAccountId": "$.detail.configurationItem.awsAccountId",
    "resource_type": "$.detail.configurationItem.resourceType",
    "resource_ID": "$.detail.configurationItem.resourceId",
    "configurationItemCaptureTime": "$.detail.configurationItem.configurationItemCaptureTime"
}

12.    在 Input Template(输入模板)文本框中,输入以下示例模板:

"On <configurationItemCaptureTime> AWS Config service recorded a deletion of the resource <resource_ID> type <resource_type> 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"

13.    选择创建

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

"On ExampleTime AWS Config service recorded a deletion of the resource ExampleID type
 ExampleResourceType in the account ExampleAccountID region ExampleRegion. For more details open the AWS Config console at https://console.aws.amazon.com/config/home?region=*ExampleRegion*#/timeline/*ExampleResourceType*/*ExampleID*/configuration"

相关信息

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

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

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