mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
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:
commit
aebce86ab2
@ -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 = `
|
||||
|
||||
@ -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 = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user