-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
aws_sns: Add support for $or operator in subscription filter policies #30524
Comments
I don't think we can forego a typing change to fix this issue, whatever we do will still break the The least invasive change would be to add a static type SubscriptionFilterMap = { [attribute: string]: SubscriptionFilter | SubscriptionFilterMap[] };
export interface SubscriptionOptions {
// ...
readonly filterPolicy? : SubscriptionFilterMap;
}
export class SubscriptionFilter {
public static and(...filters: { [attribute: string]: SubscriptionFilter }[]) {
// TODO check conflicting filter keys
return Object.assign({}, ...filters);
}
public static or(...filters: { [attribute: string]: SubscriptionFilter }[]) {
return { $or: filters };
}
// ...
} Using the new sns.Subscription(stack, 'Subscription', {
endpoint: 'endpoint',
filterPolicy: SubscriptionFilter.or(
{
color: sns.SubscriptionFilter.stringFilter({ allowlist: ['red', 'green'] }),
price: sns.SubscriptionFilter.numericFilter({ allowlist: [100] }),
},
{
color: sns.SubscriptionFilter.stringFilter({ allowlist: ['green'] }),
price: sns.SubscriptionFilter.numericFilter({ allowlist: [500] }),
},
{ color: sns.SubscriptionFilter.stringFilter({ allowlist: ['purple'] }) },
),
protocol: sns.SubscriptionProtocol.LAMBDA,
topic,
}); And also using the new sns.Subscription(stack, 'Subscription', {
endpoint: 'endpoint',
filterPolicy: SubscriptionFilter.or(
SubscriptionFilter.and(
{ color: sns.SubscriptionFilter.stringFilter({ allowlist: ['red', 'green'] }) },
{ price: sns.SubscriptionFilter.numericFilter({ allowlist: [100] }) },
),
SubscriptionFilter.and(
{ color: sns.SubscriptionFilter.stringFilter({ allowlist: ['green'] }) },
{ price: sns.SubscriptionFilter.numericFilter({ allowlist: [500] }) },
),
{ color: sns.SubscriptionFilter.stringFilter({ allowlist: ['purple'] }) },
),
protocol: sns.SubscriptionProtocol.LAMBDA,
topic,
}); Let me know if you can come up with a cleaner solution! |
any update on this? I really need to be able to us $or in my filters |
It would be lovely if we could do |
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:
However, the
filter_policy
on an SNS subscription is aMapping[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.htmlI can get my desired result, but I have to set the filter policy directly:
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
CDK version used
2.141.0
Environment details (OS name and version, etc.)
MacOS, Python 3.9.6
The text was updated successfully, but these errors were encountered: