如何使用过滤策略将cloudwatch警报从SNS主题中排除



我有一个SNS主题,它有两个订阅,一个是pagerduty API,另一个是pagerdutyEmail。我想使用该主题的订阅筛选器策略从pagerduty电子邮件订阅中排除警报。

我不确定我应该如何排除它,过滤器策略是否有类似的选项

我试着用下面的,但没有用。

"AlarmArn": [
{
"prefix": "arn:aws:cloudwatch"
}
]
}

我不认为Subscription filter policy会允许您根据警报ARN或Cloudwatch JSON负载中发送的任何其他元数据来过滤Cloudwatch警报。

过滤器策略要求在发送到SNS主题的有效负载中有一个MessageAttributes字段,该字段应包含您希望添加过滤器策略以过滤通知的属性。

CloudwatchAlarm发送的JSON负载不包含这些属性,如下面的示例负载所示:

{
"Type": "Notification",
"MessageId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"TopicArn": "arn:aws:sns:eu-west-1:000000000000:cloudwatch-alarms",
"Subject": "ALARM: "Example alarm name" in EU - Ireland",
"Message": "{"AlarmName":"Example alarm name","AlarmDescription":"Example alarm description.","AWSAccountId":"000000000000","NewStateValue":"ALARM","NewStateReason":"Threshold Crossed: 1 datapoint (10.0) was greater than or equal to the threshold (1.0).","StateChangeTime":"2017-01-12T16:30:42.236+0000","Region":"EU - Ireland","OldStateValue":"OK","Trigger":{"MetricName":"DeliveryErrors","Namespace":"ExampleNamespace","Statistic":"SUM","Unit":null,"Dimensions":[],"Period":300,"EvaluationPeriods":1,"ComparisonOperator":"GreaterThanOrEqualToThreshold","Threshold":1.0}}",
"Timestamp": "2017-01-12T16:30:42.318Z",
"SignatureVersion": "1",
"Signature": "Cg==",
"SigningCertUrl": "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.pem",
"UnsubscribeUrl": "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:000000000000:cloudwatch-alarms:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

我已经使用Cloudwatch负载中可用的一个键值对测试了一个过滤策略,但它对我不起作用

参考文档:
https://docs.aws.amazon.com/sns/latest/dg/sns-subscription-filter-policies.html

您可能需要使用首选的客户端库编写Lambda函数,并使用Pagerduty Events API来制定解决方案。

请参阅:
https://developer.pagerduty.com/docs/tools-libraries/client-libraries/https://developer.pagerduty.com/docs/events-api-v2/trigger-events/

上面的过滤器实际上将消息与前缀为arn:was:cloudwatchAlarmArn进行匹配。

您可以尝试使用anything-but命令。

"AlarmArn": [{
"anything-but": [{
"prefix": "arn.aws.cloudwatch"
}]
}]

请参阅https://docs.aws.amazon.com/sns/latest/dg/sns-subscription-filter-policies.html获取更多信息

截至目前,SNS也支持基于有效负载的消息过滤。因此,您现在可以过滤来自CloudWatch警报的事件。更多信息:https://aws.amazon.com/about-aws/whats-new/2022/11/amazon-sns-payload-based-message-filtering/

最新更新