我认为Subscription filter policy 不允许您根据警报 ARN 或 Cloudwatch JSON 有效负载中发送的任何其他元数据过滤 Cloudwatch 警报。
过滤策略需要在发送到 SNS 主题的负载中包含 MessageAttributes 字段,并且该字段应包含您希望添加过滤策略以过滤通知的属性。
Cloudwatch 警报发送的 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/