我想使用 AWS Config 在 AWS 资源被删除时接收针对服务事件类型的电子邮件通知。
解决方法
您可以使用具有 Amazon EventBridge 规则的自定义事件模式来匹配 AWS Config 支持的资源类型。然后,将响应路由到 Amazon Simple Notification Service (Amazon SNS) 主题。
在以下示例中,当 Amazon Elastic Compute Cloud (Amazon EC2) 实例被终止时,您会收到一条 Amazon SNS 通知。
**注意:**请将资源类型替换为您的特定 AWS 服务。
完成以下步骤:
-
创建 Amazon SNS 主题。
**注意:**Amazon SNS 主题必须与 AWS Config 服务位于同一 AWS 区域。
-
打开 EventBridge 控制台。
-
在导航窗格中的 Rules(规则)下,选择 Rules(规则),然后选择 Create rule(创建规则)。
-
在 Define rule detail(定义规则详细信息)页面上,输入以下信息:
对于 Name(名称),输入规则的名称。
对于 Rule type(规则类型),选择 Rule with an event pattern(具有事件模式的规则)。
-
选择 Next(下一步)。
-
对于 Event source(事件来源),选择 AWS events or EventBridge partner events(AWS 事件或 EventBridge 合作伙伴事件)。
对于 Event pattern(事件模式),选择 Custom pattern (JSON editor)(自定义模式(JSON 编辑器))。
在 Event pattern(事件模式)预览窗格中,输入以下示例事件模式:
{
"source": [
"aws.config"
],
"detail-type": [
"Config Configuration Item Change"
],
"detail": {
"messageType": [
"ConfigurationItemChangeNotification"
],
"configurationItem": {
"configurationItemStatus": [
"ResourceDeleted"
]
}
}
}
-
选择 Next(下一步)。
-
对于 Target 1(目标 1),选择 AWS service(AWS 服务)。
-
对于 Select a target(选择目标),选择 SNS topic(SNS 主题)。
-
对于 Target location(目标位置),选择 Target in this account(此账户中的目标)。
-
对于 Topic(主题),选择您的 Amazon SNS 主题。
-
在 Additional settings(其他设置)下,对于 Configure target input(配置目标输入),选择 Input transformer(输入转换器)。然后,选择 Configure input transformer(配置输入转换器)。
-
对于 Input path(输入路径),输入以下示例路径:
{
"awsRegion": "$.detail.configurationItem.awsRegion",
"awsAccountId": "$.detail.configurationItem.awsAccountId",
"resource_type": "$.detail.configurationItem.resourceType",
"resource_ID": "$.detail.configurationItem.resourceId",
"configurationItemCaptureTime": "$.detail.configurationItem.configurationItemCaptureTime"
}
- 对于 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=#/timeline///configuration”
- 选择 Confirm(确认)。
- 选择 Next(下一步)。
- 选择 Next(下一步)。
- 选择 Create rule(创建规则)。
相关信息
使用 AWS Config 创建资源时,如何接收自定义电子邮件通知?
如何为 GuardDuty 配置 EventBridge 规则,以便发送针对特定 AWS 服务事件类型的自定义 SNS 通知?