From f5610e6f2c54a92fc13c6c44b0b2f1c9627fd579 Mon Sep 17 00:00:00 2001 From: Danny Varner Date: Tue, 11 Apr 2017 16:54:36 -0700 Subject: [PATCH 1/6] Add failing test --- .../compile/events/stream/index.test.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/plugins/aws/deploy/compile/events/stream/index.test.js b/lib/plugins/aws/deploy/compile/events/stream/index.test.js index 0ebc32de7..a5abd3b18 100644 --- a/lib/plugins/aws/deploy/compile/events/stream/index.test.js +++ b/lib/plugins/aws/deploy/compile/events/stream/index.test.js @@ -135,6 +135,30 @@ describe('AwsCompileStreamEvents', () => { .IamRoleLambdaExecution ).to.equal(null); }); + it('should not throw error if custom IAM role name reference is set in function', () => { + const roleLogicalId = 'RoleLogicalId'; + awsCompileStreamEvents.serverless.service.functions = { + first: { + role: roleLogicalId, + events: [ + { + // doesn't matter if DynamoDB or Kinesis stream + stream: 'arn:aws:dynamodb:region:account:table/foo/stream/1', + }, + ], + }, + }; + + // pretend that the default IamRoleLambdaExecution is not in place + awsCompileStreamEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.IamRoleLambdaExecution = null; + + expect(() => { awsCompileStreamEvents.compileStreamEvents(); }).to.not.throw(Error); + expect(awsCompileStreamEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.FirstEventSourceMappingDynamodbFoo.DependsOn).to.equal(roleLogicalId); + expect(awsCompileStreamEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.IamRoleLambdaExecution).to.equal(null); + }); it('should not throw error if custom IAM role reference is set in function', () => { const roleLogicalId = 'RoleLogicalId'; From 7a3d9edeb28d2da6b50786ab50d88ada678a0ece Mon Sep 17 00:00:00 2001 From: Danny Varner Date: Tue, 11 Apr 2017 19:33:50 -0700 Subject: [PATCH 2/6] Fix failing test --- lib/plugins/aws/deploy/compile/events/stream/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/plugins/aws/deploy/compile/events/stream/index.js b/lib/plugins/aws/deploy/compile/events/stream/index.js index 1b6d44e33..60fdd2f1f 100644 --- a/lib/plugins/aws/deploy/compile/events/stream/index.js +++ b/lib/plugins/aws/deploy/compile/events/stream/index.js @@ -137,6 +137,9 @@ class AwsCompileStreamEvents { ) { dependsOn = `"${funcRole['Fn::GetAtt'][0]}"`; } + else { + dependsOn = `"${funcRole}"` + } } const streamTemplate = ` { From 555b2fefa6b8b10979b33e31ba894cd6005ad8ac Mon Sep 17 00:00:00 2001 From: Danny Varner Date: Tue, 11 Apr 2017 19:52:49 -0700 Subject: [PATCH 3/6] Add additional test for custom role at provider --- .../compile/events/stream/index.test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/plugins/aws/deploy/compile/events/stream/index.test.js b/lib/plugins/aws/deploy/compile/events/stream/index.test.js index a5abd3b18..49fabb481 100644 --- a/lib/plugins/aws/deploy/compile/events/stream/index.test.js +++ b/lib/plugins/aws/deploy/compile/events/stream/index.test.js @@ -243,6 +243,33 @@ describe('AwsCompileStreamEvents', () => { .Resources.IamRoleLambdaExecution).to.equal(null); }); + it('should not throw error if custom IAM role name reference is set in provider', () => { + const roleLogicalId = 'RoleLogicalId'; + awsCompileStreamEvents.serverless.service.functions = { + first: { + events: [ + { + // doesn't matter if DynamoDB or Kinesis stream + stream: 'arn:aws:dynamodb:region:account:table/foo/stream/1', + }, + ], + }, + }; + + // pretend that the default IamRoleLambdaExecution is not in place + awsCompileStreamEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.IamRoleLambdaExecution = null; + + awsCompileStreamEvents.serverless.service.provider + .role = roleLogicalId; + + expect(() => { awsCompileStreamEvents.compileStreamEvents(); }).to.not.throw(Error); + expect(awsCompileStreamEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.FirstEventSourceMappingDynamodbFoo.DependsOn).to.equal(roleLogicalId); + expect(awsCompileStreamEvents.serverless.service.provider.compiledCloudFormationTemplate + .Resources.IamRoleLambdaExecution).to.equal(null); + }); + describe('when a DynamoDB stream ARN is given', () => { it('should create event source mappings when a DynamoDB stream ARN is given', () => { awsCompileStreamEvents.serverless.service.functions = { From 47185aded8e6b637a6f8a5dfe79cd145851a8900 Mon Sep 17 00:00:00 2001 From: Danny Varner Date: Tue, 11 Apr 2017 19:53:12 -0700 Subject: [PATCH 4/6] Add type check for a string --- lib/plugins/aws/deploy/compile/events/stream/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/aws/deploy/compile/events/stream/index.js b/lib/plugins/aws/deploy/compile/events/stream/index.js index 60fdd2f1f..99b01a32e 100644 --- a/lib/plugins/aws/deploy/compile/events/stream/index.js +++ b/lib/plugins/aws/deploy/compile/events/stream/index.js @@ -137,7 +137,7 @@ class AwsCompileStreamEvents { ) { dependsOn = `"${funcRole['Fn::GetAtt'][0]}"`; } - else { + else if (typeof funcRole == 'string') { dependsOn = `"${funcRole}"` } } From fbf09e03c77c759789965da641477fc3b356533e Mon Sep 17 00:00:00 2001 From: Danny Varner Date: Tue, 11 Apr 2017 20:44:17 -0700 Subject: [PATCH 5/6] Fix lint issues --- lib/plugins/aws/deploy/compile/events/stream/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/plugins/aws/deploy/compile/events/stream/index.js b/lib/plugins/aws/deploy/compile/events/stream/index.js index 99b01a32e..9c4a645c5 100644 --- a/lib/plugins/aws/deploy/compile/events/stream/index.js +++ b/lib/plugins/aws/deploy/compile/events/stream/index.js @@ -136,9 +136,8 @@ class AwsCompileStreamEvents { funcRole['Fn::GetAtt'][1] === 'Arn' ) { dependsOn = `"${funcRole['Fn::GetAtt'][0]}"`; - } - else if (typeof funcRole == 'string') { - dependsOn = `"${funcRole}"` + } else if (typeof funcRole === 'string') { + dependsOn = `"${funcRole}"`; } } const streamTemplate = ` From 10ed9c97bb152e403ac767c06b54ef3958c9cf9e Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Thu, 13 Apr 2017 10:30:56 +0200 Subject: [PATCH 6/6] Fix whitespace --- lib/plugins/aws/package/compile/events/stream/index.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plugins/aws/package/compile/events/stream/index.test.js b/lib/plugins/aws/package/compile/events/stream/index.test.js index 49fabb481..d3b455df0 100644 --- a/lib/plugins/aws/package/compile/events/stream/index.test.js +++ b/lib/plugins/aws/package/compile/events/stream/index.test.js @@ -135,6 +135,7 @@ describe('AwsCompileStreamEvents', () => { .IamRoleLambdaExecution ).to.equal(null); }); + it('should not throw error if custom IAM role name reference is set in function', () => { const roleLogicalId = 'RoleLogicalId'; awsCompileStreamEvents.serverless.service.functions = {