Yaakov Bressler
Yaakov Bressler

Reputation: 12008

Cloudwatch: Monitoring SNS based on MessageAttribute?

I have several backend services which publish to a single SNS topic. The specific publishing service is designated as a field in MessageAttributes. Conversely, I have a single consumer subscribed to all messages from this topic.

I'd like to monitor this SNS topic in Cloudwatch to determine if the number of messages being published per backend service is as expected. Is there a way for me to partition this information in cloudwatch based on a value in message attributes?

Note: I am aware that Cloudwatch can monitor number of messages based on SNS Filter Policies. My concern is that I have a single consumer – would creating additional filter policies be expensive/wasteful?

Upvotes: -1

Views: 619

Answers (1)

lprentice
lprentice

Reputation: 204

The filter policy metrics sadly do not support the granularity you are looking for at a policy level. In order to keep the metrics within Cloudwatch you could use a Lambda that processes the messages on the topic and generates custom metrics into Cloudwatch based on the Attribute you are interested in making it possible to use in dashboards and alarms.

At a high-level the flow would be SNS -> Lambda -> Cloudwatch. Rather than using the CloudWatch API to push the metrics you could make use of the Cloudwatch embedded metric format.

Depending on your setup you could instead add metrics into the backend services that are making the PublishMessage calls. At least this way no new components would be needed to capture the metrics.

Upvotes: 2

Related Questions