Skip to content

Commit

Permalink
fix(sns): cannot use numeric filter policy with 0 values (#16551)
Browse files Browse the repository at this point in the history
Closes #16549


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold authored Sep 27, 2021
1 parent 851c8ca commit 62b6762
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-sns/lib/subscription-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ export class SubscriptionFilter {
conditions.push(...allowlist.map(v => ({ numeric: ['=', v] })));
}

if (numericConditions.greaterThan) {
if (numericConditions.greaterThan !== undefined) {
conditions.push({ numeric: ['>', numericConditions.greaterThan] });
}

if (numericConditions.greaterThanOrEqualTo) {
if (numericConditions.greaterThanOrEqualTo !== undefined) {
conditions.push({ numeric: ['>=', numericConditions.greaterThanOrEqualTo] });
}

if (numericConditions.lessThan) {
if (numericConditions.lessThan !== undefined) {
conditions.push({ numeric: ['<', numericConditions.lessThan] });
}

if (numericConditions.lessThanOrEqualTo) {
if (numericConditions.lessThanOrEqualTo !== undefined) {
conditions.push({ numeric: ['<=', numericConditions.lessThanOrEqualTo] });
}

Expand Down
34 changes: 34 additions & 0 deletions packages/@aws-cdk/aws-sns/test/subscription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,40 @@ describe('Subscription', () => {

});

test('with numeric filter and 0 values', () => {
// GIVEN
const stack = new cdk.Stack();
const topic = new sns.Topic(stack, 'Topic');

// WHEN
new sns.Subscription(stack, 'Subscription', {
endpoint: 'endpoint',
filterPolicy: {
price: sns.SubscriptionFilter.numericFilter({
greaterThan: 0,
greaterThanOrEqualTo: 0,
lessThan: 0,
lessThanOrEqualTo: 0,
}),
},
protocol: sns.SubscriptionProtocol.LAMBDA,
topic,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::SNS::Subscription', {
FilterPolicy: {
price: [
{ numeric: ['>', 0] },
{ numeric: ['>=', 0] },
{ numeric: ['<', 0] },
{ numeric: ['<=', 0] },
],
},
});

});

test('with existsFilter', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 62b6762

Please sign in to comment.