From 62b6762195324cf04758ab96ed20925b4939b773 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Mon, 27 Sep 2021 16:36:45 +0200 Subject: [PATCH] fix(sns): cannot use numeric filter policy with 0 values (#16551) Closes #16549 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-sns/lib/subscription-filter.ts | 8 ++--- .../aws-sns/test/subscription.test.ts | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-sns/lib/subscription-filter.ts b/packages/@aws-cdk/aws-sns/lib/subscription-filter.ts index c6fc1be95d247..69be08bb1db26 100644 --- a/packages/@aws-cdk/aws-sns/lib/subscription-filter.ts +++ b/packages/@aws-cdk/aws-sns/lib/subscription-filter.ts @@ -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] }); } diff --git a/packages/@aws-cdk/aws-sns/test/subscription.test.ts b/packages/@aws-cdk/aws-sns/test/subscription.test.ts index a495769648d4b..dd0f9588d2296 100644 --- a/packages/@aws-cdk/aws-sns/test/subscription.test.ts +++ b/packages/@aws-cdk/aws-sns/test/subscription.test.ts @@ -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();