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.

dnt994
已提問 2 年前檢視次數 1105 次
1 個回答
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

已回答 2 年前
  • 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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南