diff --git a/lib/plugins/aws/package/compile/events/stream/index.js b/lib/plugins/aws/package/compile/events/stream/index.js index a0bb4ab36..695d88f18 100644 --- a/lib/plugins/aws/package/compile/events/stream/index.js +++ b/lib/plugins/aws/package/compile/events/stream/index.js @@ -136,6 +136,8 @@ class AwsCompileStreamEvents { funcRole['Fn::GetAtt'][1] === 'Arn' ) { dependsOn = `"${funcRole['Fn::GetAtt'][0]}"`; + } else if (typeof funcRole === 'string') { + dependsOn = `"${funcRole}"`; } } const streamTemplate = ` 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 0ebc32de7..d3b455df0 100644 --- a/lib/plugins/aws/package/compile/events/stream/index.test.js +++ b/lib/plugins/aws/package/compile/events/stream/index.test.js @@ -136,6 +136,31 @@ describe('AwsCompileStreamEvents', () => { ).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'; awsCompileStreamEvents.serverless.service.functions = { @@ -219,6 +244,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 = {