From edc4e1e7156c1627b9ec9c48b18200056d644750 Mon Sep 17 00:00:00 2001 From: Sameer Suri Date: Thu, 18 Jul 2019 13:20:27 -0700 Subject: [PATCH] Changed AWS subscription filters to use function object name --- lib/plugins/aws/deploy/lib/checkForChanges.js | 12 ++--- .../aws/deploy/lib/checkForChanges.test.js | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/lib/plugins/aws/deploy/lib/checkForChanges.js b/lib/plugins/aws/deploy/lib/checkForChanges.js index ec4419c25..1ef505344 100644 --- a/lib/plugins/aws/deploy/lib/checkForChanges.js +++ b/lib/plugins/aws/deploy/lib/checkForChanges.js @@ -149,8 +149,6 @@ module.exports = { */ checkLogGroupSubscriptionFilterResourceLimitExceeded() { const region = this.provider.getRegion(); - const serviceName = this.serverless.service.getServiceName(); - const stage = this.provider.getStage(); const cloudWatchLogsSdk = new this.provider.sdk.CloudWatchLogs({ region }); return this.provider.getAccountId().then(accountId => @@ -187,10 +185,8 @@ module.exports = { cloudWatchLogsSdk, accountId, logGroupName, - functionName, + functionObj, region, - serviceName, - stage, }); }); @@ -204,10 +200,8 @@ module.exports = { const cloudWatchLogsSdk = params.cloudWatchLogsSdk; const accountId = params.accountId; const logGroupName = params.logGroupName; - const functionName = params.functionName; + const functionObj = params.functionObj; const region = params.region; - const serviceName = params.serviceName; - const stage = params.stage; return ( cloudWatchLogsSdk @@ -223,7 +217,7 @@ module.exports = { const oldDestinationArn = subscriptionFilter.destinationArn; const filterName = subscriptionFilter.filterName; - const newDestinationArn = `arn:aws:lambda:${region}:${accountId}:function:${serviceName}-${stage}-${functionName}`; + const newDestinationArn = `arn:aws:lambda:${region}:${accountId}:function:${functionObj.name}`; // everything is fine, just return if (oldDestinationArn === newDestinationArn) { diff --git a/lib/plugins/aws/deploy/lib/checkForChanges.test.js b/lib/plugins/aws/deploy/lib/checkForChanges.test.js index 9cc808d38..313c4c924 100644 --- a/lib/plugins/aws/deploy/lib/checkForChanges.test.js +++ b/lib/plugins/aws/deploy/lib/checkForChanges.test.js @@ -577,6 +577,8 @@ describe('checkForChanges', () => { }, }; + awsDeploy.serverless.service.setFunctionNames(); + describeSubscriptionFiltersResponse = { subscriptionFilters: [], }; @@ -593,6 +595,8 @@ describe('checkForChanges', () => { }, }; + awsDeploy.serverless.service.setFunctionNames(); + describeSubscriptionFiltersResponse = { subscriptionFilters: [ { @@ -614,6 +618,8 @@ describe('checkForChanges', () => { }, }; + awsDeploy.serverless.service.setFunctionNames(); + describeSubscriptionFiltersResponse = { subscriptionFilters: [ { @@ -627,6 +633,54 @@ describe('checkForChanges', () => { .checkForChanges() .then(() => expect(deleteSubscriptionFilterStub).to.have.been.called); }); + + it('should not call delete if there is a subFilter and the ARNs are the same with custom function name', () => { + awsDeploy.serverless.service.functions = { + first: { + name: 'my-test-function', + events: [{ cloudwatchLog: '/aws/lambda/hello1' }], + }, + }; + + awsDeploy.serverless.service.setFunctionNames(); + + describeSubscriptionFiltersResponse = { + subscriptionFilters: [ + { + destinationArn: `arn:aws:lambda:${region}:${accountId}:function:my-test-function`, + filterName: 'dummy-filter', + }, + ], + }; + + return awsDeploy + .checkForChanges() + .then(() => expect(deleteSubscriptionFilterStub).to.not.have.been.called); + }); + + it('should call delete if there is a subFilter but the ARNs are not the same with custom function name', () => { + awsDeploy.serverless.service.functions = { + first: { + name: 'my-test-function', + events: [{ cloudwatchLog: '/aws/lambda/hello1' }], + }, + }; + + awsDeploy.serverless.service.setFunctionNames(); + + describeSubscriptionFiltersResponse = { + subscriptionFilters: [ + { + destinationArn: `arn:aws:lambda:${region}:${accountId}:function:my-other-test-function`, + filterName: 'dummy-filter', + }, + ], + }; + + return awsDeploy + .checkForChanges() + .then(() => expect(deleteSubscriptionFilterStub).to.have.been.called); + }); }); }); });