下图是我想要实现的。简而言之,将 CloudTrail 日志发送到 CloudWatch 日志组,然后对其进行扫描以查找某些事件,最后在发生协同事件时发送电子邮件警报。
我正在关注这个官方文档,其中也有一个示例 CloudFormation 模板:http ://docs.aws.amazon.com/awscloudtrail/latest/userguide/use-cloudformation-template-to-create-cloudwatch-alarms.html
使用上面的 CloudFormation 模板,我已经能够发送电子邮件警报。然而,警报是非常基本的;它不会发送关键信息,例如哪个用户发起了此事件、何时发生等。
逻辑思维AWS::Logs::MetricFilter
应该传递值AWS::CloudWatch::Alarm
,然后将信息发送到该值。我查看了两者的文档MetricFilter
和Alarm
服务。Dimension
更接近我想要的,但还不能从日志中读取信息。
我原以为这是一个常见的用例,并且会有文档。我在这里错过了什么明显的东西吗?这里有人解决了这个问题吗?
AWS::Logs::MetricFilter
堵塞:
"AuthorizationFailuresMetricFilter": {
"Type": "AWS::Logs::MetricFilter",
"Properties": {
"LogGroupName": { "Ref" : "LogGroupName" },
"FilterPattern": "{ ($.errorCode = \"*UnauthorizedOperation\") || ($.errorCode = \"AccessDenied*\") }",
"MetricTransformations": [
{
"MetricNamespace": "CloudTrailMetrics",
"MetricName": "AuthorizationFailureCount",
"MetricValue": "1"
}
]
}
},
AWS::CloudWatch::Alarm
堵塞
"AuthorizationFailuresAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmName" : "CloudTrailAuthorizationFailures",
"AlarmDescription" : "Alarms when an unauthorized API call is made.",
"AlarmActions" : [{ "Ref" : "AlarmNotificationTopic" }],
"Dimensions": [
{
"Name": "errorCode",
"Value": ""
},
{
"Name": "userIdentity",
"Value": ""
}
],
"MetricName" : "AuthorizationFailureCount",
"Namespace" : "CloudTrailMetrics",
"ComparisonOperator" : "GreaterThanOrEqualToThreshold",
"EvaluationPeriods" : "1",
"Period" : "300",
"Statistic" : "Sum",
"Threshold" : "1"
}
},