We are using an SNS topic that is shared through enterprise for different project and it has to be that way, but with everyone using that SNS topic in cloudwatch alarms. we get email notifications for all the alarms which we dont want, we want to receive the notifications for just our alarms.
the solution could be to add a filter on the subscription but the message coming from cloudwatch alarm doesn't have any message attributes on which we can put the filter. Can anyone please suggest a solution for the problem or let me know if there is a way to add the custom message attributes based on which we can filter.
CodePudding user response:
It is not possible to filter messages that come from CloudWatch. I had the same issue recently. In order to filter messages in SNS the topic, it must have appropriate Message Attributes.
What you can do is this:
- Create Lambda function (give it permission to send messages to the SNS topic)
- Point your CloudWatch alarms to send an alarm to the Lambda function
- In your Lambda function write the parser that would recognize for which project the message is supposed to be
- From the Lambda function publish a message to the SNS topic and add a Message Attribute that you can use in SNS for filtering