Arafat Nalkhande
Arafat Nalkhande

Reputation: 11718

AWS SNS Message filtering on 'OR' condition

On the SNS Message filtering page there is an example for AND/OR Logic as follows

AND logic : Apply AND logic by using multiple attribute names (keys). For example, the policy:

{
    "customer_interests": ["rugby"],
    "price_usd": [{"numeric":[">", 100]}]
}

OR logic : Apply OR logic by assigning multiple values to an attribute name. For example, the policy attribute:

"customer_interests": ["rugby", "football", "baseball"]

However how can we apply 'OR' logic for multiple attribute names (keys)

So for example what will be the policy if I want to change the first example

From

(customer_interests="rugby" AND price_usd > 100)

To

(customer_interests="rugby" OR price_usd > 100)

Upvotes: 6

Views: 5159

Answers (4)

Otavio Ferreira
Otavio Ferreira

Reputation: 966

As of Nov 2023, you can now use the “OR” operator in SNS filter policies. More information: https://aws.amazon.com/about-aws/whats-new/2023/11/amazon-sns-message-additional-filtering-operators/

Upvotes: 1

Alazar
Alazar

Reputation: 19

I may be late for the party. One alternate solution I see is to create two sqs between sns and whatever is subscribing to sns. Then, you attach the filter to sqs. And the lambda will read from sqs. This way you don't to have two end points on lambda. But this one is a bit costly.

Upvotes: 0

BachTonThat
BachTonThat

Reputation: 1

I using lambda so I can create new alias for each lambda subscrible. Each lambda will be update with LASTEST. Subscrible 1.

{
    "key1": ["01"],
    "key2": ["123"],
}

subscrible: Lambda ABC_1

Subscrible 2.

{
    "key1": ["02"],
    "key2": ["456"],
}

subscrible: Lambda ABC_1:testing

Upvotes: 0

Caldazar
Caldazar

Reputation: 3802

You would have to create 2 separate subscriptions to same endpoint and attach different filters:

For 1st subscription:

{
    "customer_interests": ["rugby"]
}

For 2nd subscription:

{   
   "price_usd": [{"numeric":[">", 100]}]
}

I didn't find any way of having OR in single filter, but with creating multiple subscriptions to same endpoint definitely works (used it mysqlf on my account)

Upvotes: 4

Related Questions