Amazon web services 如何在CloudFormation yaml模板中从CloudWatch为CloudFront设置警报?
我想设置一个警报,以防CloudWatch的CloudFront出现错误 在控制台中,我会直接创建一个警报,如果Amazon web services 如何在CloudFormation yaml模板中从CloudWatch为CloudFront设置警报?,amazon-web-services,amazon-cloudformation,amazon-cloudwatch,amazon-cloudwatch-metrics,Amazon Web Services,Amazon Cloudformation,Amazon Cloudwatch,Amazon Cloudwatch Metrics,我想设置一个警报,以防CloudWatch的CloudFront出现错误 在控制台中,我会直接创建一个警报,如果TotalErrorRate大于0,它会向我发送一封电子邮件。这很好用 但是现在我想在CloudFormation中的yaml模板文件中设置相同的设置。我很难找出相应参数的正确值。我的文件当前如下所示: # CloudWatch CloudFrontTotalErrorRateAlarm: Type: "AWS::CloudWatch::Alarm" Prope
TotalErrorRate
大于0,它会向我发送一封电子邮件。这很好用
但是现在我想在CloudFormation中的yaml模板文件中设置相同的设置。我很难找出相应参数的正确值。我的文件当前如下所示:
# CloudWatch
CloudFrontTotalErrorRateAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: Boolean
AlarmActions:
- String
AlarmDescription: "Trigers an alarm if there is any error (e.g. 4xx,5xx)"
AlarmName: "MyApiTotalErrorRate"
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Dimension
EvaluationPeriods: "1"
ExtendedStatistic: String
InsufficientDataActions:
- String
MetricName: TotalErrorRate
Namespace: AWS/CloudFront
OKActions:
- String
Period: 60
Statistic: String
Threshold: 0
TreatMissingData: String
Unit: String
AWSTemplateFormatVersion: 2010-09-09
Parameters:
DistributionId:
Type: String
Resources:
EscalationTopic:
Type: AWS::SNS::Topic
EscalationTopicEmailSubscriber:
Type: AWS::SNS::Subscription
Properties:
Endpoint: john.doe@example.com
Protocol: email
TopicArn: !Ref EscalationTopic
CloudFrontTotalErrorRateAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
Namespace: AWS/CloudFront
MetricName: TotalErrorRate
Dimensions:
- Name: DistributionId
Value: !Ref DistributionId
Statistic: Sum
Period: 60
EvaluationPeriods: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
Threshold: 1
AlarmActions:
- !Ref EscalationTopic
对于一些参数,我可以计算出实际值。但对于其他人,我基本上不知道我应该输入什么,以便AWS在发生错误时向我发送电子邮件。以下参数缺少值:
已启用操作
AlarmActions
尺寸
ExtendedStatistic
不足数据操作
ok操作
统计数据
TreatMissingData
单元
SNS主题
,将您的电子邮件地址作为一个订户:
EscalationTopic:
Type: AWS::SNS::Topic
EscalationTopicEmailSubscriber:
Type: AWS::SNS::Subscription
Properties:
Endpoint: john.doe@example.com
Protocol: email
TopicArn: !Ref EscalationTopic
作为第二步,您需要向CF模板提供分发ID
(只要分发不是CF模板的一部分):
最后,您必须将所有东西都插在一起,并通过以下方式配置CloudWatch报警
:
CloudFrontTotalErrorRateAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
Namespace: AWS/CloudFront
MetricName: TotalErrorRate
Dimensions:
- Name: DistributionId
Value: !Ref DistributionId
Statistic: Sum
Period: 60
EvaluationPeriods: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
Threshold: 1
AlarmActions:
- !Ref EscalationTopic
“最终”CF模板可能如下所示:
# CloudWatch
CloudFrontTotalErrorRateAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
ActionsEnabled: Boolean
AlarmActions:
- String
AlarmDescription: "Trigers an alarm if there is any error (e.g. 4xx,5xx)"
AlarmName: "MyApiTotalErrorRate"
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Dimension
EvaluationPeriods: "1"
ExtendedStatistic: String
InsufficientDataActions:
- String
MetricName: TotalErrorRate
Namespace: AWS/CloudFront
OKActions:
- String
Period: 60
Statistic: String
Threshold: 0
TreatMissingData: String
Unit: String
AWSTemplateFormatVersion: 2010-09-09
Parameters:
DistributionId:
Type: String
Resources:
EscalationTopic:
Type: AWS::SNS::Topic
EscalationTopicEmailSubscriber:
Type: AWS::SNS::Subscription
Properties:
Endpoint: john.doe@example.com
Protocol: email
TopicArn: !Ref EscalationTopic
CloudFrontTotalErrorRateAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
Namespace: AWS/CloudFront
MetricName: TotalErrorRate
Dimensions:
- Name: DistributionId
Value: !Ref DistributionId
Statistic: Sum
Period: 60
EvaluationPeriods: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
Threshold: 1
AlarmActions:
- !Ref EscalationTopic
我遇到了以下错误:
用户无权在资源上执行:SNS:CreateTopic(服务:AmazonSNS;状态代码:403;错误代码:AuthorizationError
。我必须添加策略吗?如果是,在哪里?作为用户,您似乎没有这样做的权限。我如何更改它?我希望在CloudInformation中更改权限。是否可能?您必须要求帐户所有者授予您的帐户权限。)权限。帮我找到了答案