【问题标题】:How to exclude cloudwatch alarns from SNS topic using filter policy?如何使用过滤策略从 SNS 主题中排除 cloudwatch 警报?
【发布时间】:2021-03-02 00:16:07
【问题描述】:

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

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

我尝试在下面使用但不起作用。

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

【问题讨论】:

  • 您想保持两个订阅都处于活动状态并且在触发 SNS 时应该排除它?您可以进行非活动电子邮件订阅。

标签: amazon-web-services amazon-cloudwatch amazon-sns cloudwatch-alarms


【解决方案1】:

上面的过滤器实际上匹配带有AlarmArn前缀arn:was:cloudwatch的消息。

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

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

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

【讨论】:

    【解决方案2】:

    我认为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/

    【讨论】:

      猜你喜欢
      • 2019-08-17
      • 1970-01-01
      • 2017-12-14
      • 2021-08-28
      • 2022-01-15
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多