SNS FilterPolicy with attribute deserialization before comparisons

0

Is there a possibility to configure SNS FilterPolicy to compare attributes within serialized fields? Example:

Message: { "Newimage": "{\"Origin\":\"XPTO\"}" }

Something like the example below, but make do sure the field is deserialized before the comparison.

FilterPolicyScope: MessageBody

FilterPolicy: ' { "Newimage": [ { "Origin": "XPTO" } ] } '

If not, how to deserialize in the FilterPolicy, can you indicate any AWS alternative? Thanks.

2 Answers
2

Amazon SNS does not currently support deserialization or complex parsing of message attributes within its FilterPolicy. The FilterPolicy is designed to work with simple key-value pairs, where the values are strings, numbers, or arrays of strings/numbers.

In your case, since the Newimage attribute contains a serialized JSON string, you would need to handle the deserialization and further processing in your subscriber after receiving the message.

If you need more advanced filtering capabilities before the message reaches your subscriber, you might consider using a different AWS service, such as Amazon Kinesis Data Firehose or AWS Lambda, to preprocess the messages. This would involve publishing the messages to a Kinesis stream or invoking a Lambda function directly, where you can perform the deserialization and filtering logic before forwarding the relevant messages to the final SNS topic or another endpoint.

Resources:

profile picture
EXPERT
answered a month ago
1

As Already mentioned above, it is true that Amazon SNS Filter Policy currently doesn't support deserialising fields within serialised data before comparison. You would need to use other service like AWS Lambda to process the message before sending to it the SNS topic where filter policy is applied for a subscription.

Please feel free to look into the overview of a possible custom solution using AWS Lambda that may fit your usecase,

  1. Configure SNS to trigger a Lambda function when a message is published to a specific topic.
  2. In the Lambda function, deserialise the message or perform the message processing logic(like comparison).
  3. Based on the functions logic, take the desired action (e.g., publish to another SNS topic, invoke another AWS service).

[+] Using AWS Lambda with Amazon SNS - https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html

AWS
answered a month ago

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