Skip to content

Commit dbf0134

Browse files
jogoldmergify[bot]
authored andcommitted
feat(sns): add support for attribute key matching in message filtering (#3709)
* feat(sns): add support for attribute key matching in message filtering SNS message filtering now supports attribute key matching. This feature lets you create an Amazon SNS subscription filter policy that matches incoming messages which contain an attribute key, regardless of the attribute value associated with this key. This feature lets you offload additional message filtering logic to Amazon SNS. Update `SubscriptionFilter` to support this new feature. See https://aws.amazon.com/about-aws/whats-new/2019/08/amazon-sns-message-filtering-adds-support-for-attribute-key-matching/ * update README * add new test for existsFilter
1 parent e9f46da commit dbf0134

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

packages/@aws-cdk/aws-sns/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const fn = new lambda.Function(this, 'Function', ...);
5757
// color: 'red' or 'orange' or begins with 'bl'
5858
// size: anything but 'small' or 'medium'
5959
// price: between 100 and 200 or greater than 300
60+
// store: attribute must be present
6061
topic.subscribeLambda(new subs.LambdaSubscription(fn, {
6162
filterPolicy: {
6263
color: sns.SubscriptionFilter.stringFilter({
@@ -69,7 +70,8 @@ topic.subscribeLambda(new subs.LambdaSubscription(fn, {
6970
price: sns.SubscriptionFilter.numericFilter({
7071
between: { start: 100, stop: 200 },
7172
greaterThan: 300
72-
})
73+
}),
74+
store: sns.SubscriptionFilter.existsFilter(),
7375
}
7476
}));
7577
```

packages/@aws-cdk/aws-sns/lib/subscription-filter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,12 @@ export class SubscriptionFilter {
135135
return new SubscriptionFilter(conditions);
136136
}
137137

138+
/**
139+
* Returns a subscription filter for attribute key matching.
140+
*/
141+
public static existsFilter() {
142+
return new SubscriptionFilter([{ exists: true }]);
143+
}
144+
138145
constructor(public readonly conditions: any[] = []) {}
139146
}

packages/@aws-cdk/aws-sns/test/test.subscription.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ export = {
8080
test.done();
8181
},
8282

83+
'with existsFilter'(test: Test) {
84+
// GIVEN
85+
const stack = new cdk.Stack();
86+
const topic = new sns.Topic(stack, 'Topic');
87+
88+
// WHEN
89+
new sns.Subscription(stack, 'Subscription', {
90+
endpoint: 'endpoint',
91+
filterPolicy: {
92+
size: sns.SubscriptionFilter.existsFilter(),
93+
},
94+
protocol: sns.SubscriptionProtocol.LAMBDA,
95+
topic
96+
});
97+
98+
// THEN
99+
expect(stack).to(haveResource('AWS::SNS::Subscription', {
100+
FilterPolicy: {
101+
size: [{ exists: true }]
102+
},
103+
}));
104+
test.done();
105+
},
106+
83107
'throws with raw delivery for protocol other than http, https or sqs'(test: Test) {
84108
// GIVEN
85109
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)