Merge pull request #3457 from piohhmy/fix-depends-on-with-event-stream

Fix Event Streams when functions have direct reference to custom roles
This commit is contained in:
Philipp Muens 2017-04-13 10:50:29 +02:00 committed by GitHub
commit aebce86ab2
2 changed files with 54 additions and 0 deletions

View File

@ -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 = `

View File

@ -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 = {