如何配置 CloudWatch Events 规则,以便在特定 AWS 服务事件类型触发时让 GuardDuty 发送自定义的 SNS 通知?
上次更新时间:2019 年 5 月 22 日
我创建了一条 Amazon CloudWatch Events 规则,以根据 Amazon GuardDuty 服务事件类型触发,但响应为 JSON 格式。如何才能收到含有自定义通知的电子邮件响应?
简短描述
在 CloudWatch Events 规则中使用自定义事件模式,从而匹配特定的调查结果类型。然后,将响应路由到某个 Amazon Simple Notification Service (Amazon SNS) 主题。
解决方法
此示例使用 Amazon GuardDuty 事件类型 UnauthorizedAccess:EC2/TorIPCaller。
注意:您可以将它替换为特定 AWS 服务的服务名称和事件类型。
1. 如果您尚未创建 Amazon SNS 主题,请按照 Amazon SNS 入门中的说明创建一个。
注意:Amazon SNS 主题必须与您的 AWS GuardDuty 服务位于同一区域。
2. 打开 CloudWatch 控制台。
3. 在导航窗格中,选择规则,然后选择创建规则。
4. 在服务名称菜单中,选择 GuardDuty。
5. 在事件类型菜单中,选择 GuardDuty 调查结果。
6. 在事件模式预览中,选择编辑。
7. 复制以下代码并将其粘贴到事件模式预览中,然后选择保存。
{
"source": ,
"detail": {
"type":
}
}
8. 在目标下,选择添加目标。
9. 在选择目标中,选择 SNS 主题。
10. 在选择主题中,选择您的 SNS 主题。
11. 展开配置输入,然后选择输入转换器。
12. 复制下面的代码。然后将其粘贴到输入路径中。
{
"severity": "$.detail.severity",
"Finding_ID": "$.detail.id",
"instanceId": "$.detail.resource.instanceDetails.instanceId",
"port": "$.detail.service.action.networkConnectionAction.localPortDetails.port",
"eventFirstSeen": "$.detail.service.eventFirstSeen",
"eventLastSeen": "$.detail.service.eventLastSeen",
"count": "$.detail.service.count",
"Finding_Type": "$.detail.type",
"region": "$.region",
"Finding_description": "$.detail.description"
}
13. 复制下面的代码。然后将其粘贴到输入模板中。
"You have a severity <severity> GuardDuty finding type <Finding_Type> for the EC2 instance <instanceId> in the region <region> as the <Finding_description> on the port <port>. The first attempt was on <eventFirstSeen> and the most recent attempt on <eventLastSeen> . The total occurrence is <count>. For more details open the GuardDuty console at https://console.aws.amazon.com/guardduty/home?region=<region>#/findings?search=id%3D<Finding_ID>"
14.选择配置详细信息。
15.在配置规则详细信息中,输入规则的名称和描述,然后选择创建规则。
16.触发某个事件类型时,您将收到一份 SNS 电子邮件通知,其中的自定义字段将从第 13 步填充,与以下所示类似:
"You have a severity 5 GuardDuty finding type UnauthorizedAccess:EC2/TorIPCaller for the EC2 instance EXAMPLEID in the region EXAMPLEREGION as the IP address 192.0.2.0/2 on the Tor Anonymizing Proxy network is communicating with EC2 instance EXAMPLEID. on the port 80. The first attempt was on 2019-04-09T00:01:14.681Z and the most recent attempt on 2019-05-20T06:04:12.593Z . The total occurrence is 5. For more details open the GuardDuty console at https://console.aws.amazon.com/guardduty/home?EXAMPLEREGION"