aws / aws/aws-cdk

aws_sns: Add support for $or operator in subscription filter policies

Open
#30,524 7 comments 9 reactions 0 assignees View on GitHub
@aws-cdk/aws-sns effort/medium feature-request p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

https://docs.aws.amazon.com/sns/latest/dg/and-or-logic.html#or-operator

I would like to be able to use the "$or" operator for SNS subscription filters to filter out messages based on multiple combinations of message attributes.

### Use Case

I would like to create the following filter policy on an SNS subscription:

```json
{
"$or": [
{
"attribute_1": [
"value_1",
"value_2"
]
},
{
"attribute_1": [
"value_3"
],
"attribute_2": [
"value_4"
]
}
]
}
```

However, the `filter_policy` on an SNS subscription is a `Mapping[str, SubscriptionFilter]`, which doesn't account for the "$or" operator which effectively takes a list of filter policies. https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_sns/Subscription.html

I can get my desired result, but I have to set the filter policy directly:
```python
subscription = self._topic.add_subscription(
aws_sns_subscriptions.SqsSubscription(
self._queue,
)
)

subscription.node.default_child.filter_policy = filter_policy
```
where filter_policy is the dictionary at the beginning of the section.

I was unable to find if this was already supported in the documentation.

### Proposed Solution

_No response_

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.141.0

### Environment details (OS name and version, etc.)

MacOS, Python 3.9.6

Contributor guide

Open the contributing guide

Research direction

Start at the aws_sns Subscription filter_policy entry point and compare it with SqsSubscription and the generated Python API referenced in the issue. Check the AWS SNS $or operator documentation, then verify that the public filter-policy type accepts the example and that the synthesized subscription policy preserves its structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, typescript
Domain
cloud, devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.