【发布时间】:2021-08-02 06:18:48
【问题描述】:
如何为指标过滤器创建警报并连接 SNS 主题。
我的任务是:
- 创建 SNS 主题和电子邮件订阅
- 创建 CloudWatch 日志组
- 为该 CloudWatch 日志组创建指标过滤器并创建警报并连接 SNS 主题
AWSTemplateFormatVersion: "2010-09-09"
#Parameters:
#EmailAddress:
#Type: String
#Description: The email address to use for alarm notifications.
Resources:
# Create SNS and email subscription
MySNSTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: "abcd@abc.com"
Protocol: email
# Create CloudWatch log group
snstopic:
Type: AWS::Logs::LogGroup
DependsOn: MySNSTopic
Properties:
RetentionInDays: 7
# Create metric filter
UnauthorizedApiCalls:
Type: AWS::Logs::MetricFilter
DependsOn: snstopic
Properties:
LogGroupName:
Ref: "snstopic"
FilterPattern: '{($.errorCode="*UnauthorizedOperation") || ($.errorCode="AccessDenied*")}'
MetricTransformations:
- MetricValue: "1"
MetricNamespace: "unauthorized-api-calls"
MetricName: "LogMetrics"
# Create alarm
UnauthorizedApiCallsAlarm:
Type: AWS::CloudWatch::Alarm
DependsOn: UnauthorizedApiCalls
Properties:
AlarmName: UnauthorizedApiCallsAlarm
AlarmActions: !Ref snstopic
MetricName: UnauthorizedApiCalls
Namespace: LogMetrics
ComparisonOperator: GreaterThanOrEqualToThreshold
EvaluationPeriods: '1'
Period: '5'
Statistic: Sum
Threshold: '1'
TreatMissingData: breaching
【问题讨论】:
-
你试过这个cfn yaml吗?您面临的问题是什么?
-
不在 cloudwatch 日志组中创建警报。
-
我认为我的“创建警报”yaml 代码是错误的。你能解决这个问题吗?
-
为什么你认为它错了?到底发生了什么?有任何错误信息吗?
标签: amazon-web-services amazon-cloudformation alarm