gpt4 book ai didi

amazon-web-services - 如何使用 CloudFormation 在指标过滤器中设置警报

转载 作者:行者123 更新时间:2023-12-03 07:30:45 28 4
gpt4 key购买 nike

如何为指标过滤器创建警报并连接 SNS 主题。

我的任务是:

  1. 创建 SNS 主题和电子邮件订阅
  2. 创建 CloudWatch 日志组
  3. 为该 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: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5a3b38393e1a3b383974393537" rel="noreferrer noopener nofollow">[email protected]</a>"
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

最佳答案

试试这个。根据documentationAlarmActions 的类型是 List of String

# 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

关于amazon-web-services - 如何使用 CloudFormation 在指标过滤器中设置警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68617130/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com