Send Object as sns message attribute

0

I'd like to publish a message to my sns topic.
I'm using js "aws-sdk/client-sns" with the snsClient.send(new PublishCommand(params).
Subscribed to my sns topic there is a sqs queue with a filter sub policy.
The issue is with the message attributes, I want to send as value a json object as in this example:
MessageAttributes: { filter: { DataType: 'String', StringValue: "filter" } }, object: { DataType: 'String', StringValue: JSON.stringify( object ) } }
the message never get to the queue and fails under "NumberOfNotificationsFilteredOut" or "NumberOfNotificationsFilteredOut-InvalidAttributes".
Instead, if the queue does not have a filter sub policy or I set the object as DataType: 'String.Array'the message arrive without any problem, is this a bug? How should I set my message attribute if I want to send an Object ? Thanks.

1 Answer
0

Amazon SNS compares policy attributes only to message attributes that have the following data types:

  1. String
  2. String.Array
  3. Number

for more details see: https://docs.aws.amazon.com/sns/latest/dg/subscription-filter-policy-constraints.html

answered a year ago
  • Thanks for the info, but this is not what I'm looking for, I want to know if there is a correct way to send an Object as a message attribute, and why if sent as "DataType: String" is messing up with the filter policy, while with "String.Array" there is no problem.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions