Search code examples
amazon-web-servicesamazon-snsamazon-elasticache

How to filter SNS message sent by Elasticache?


I need to monitor an Elasticache replication group with SNS + Pagerduty. Problem is Elasticache sends all events to configured sns arn without differentiating whether it's a serious event like ElastiCache:SnapshotFailed or a normal one as ElastiCache:CacheClusterParametersChanged.

I tried to attach a filter policy to the subscription of the topic, unfortunately the the filtering only works for message which contains a "MessageAttributes" field as mentioned in https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html. So it doesn't work for me.

The message send by Elasticache is like:

{
  "Type" : "Notification",
  "MessageId" : "93cc4ffe-bbd7-521e-8dd1-1c25d437dc1b",
  "TopicArn" : "arn:aws:sns:eu-central-1:custid:redis-monitor-a",
  "Message" : "{\"ElastiCache:SnapshotComplete\":\"redis-a-001\"}",
  "Timestamp" : "2018-08-01T08:21:52.610Z",
  "SignatureVersion" : "1",
  "Signature" : "aaabbbccc",
  "SigningCertURL" : "xxxbbbzzz",
  "UnsubscribeURL" : "yyyzzzaaa"
}


Solution

  • As you correctly pointed out SNS message filtering works based on message attributes.

    So basically if elasticache is not setting any MessageAttributes then message filtering cannot be done

    The only option left with you is to read the messages in the subscribers and then ignore the ones that you don't want