Skip to content

Commit 29f0e9c

Browse files
committed
fix: Dont depend on default execution role when custom role provided
1 parent dee54ed commit 29f0e9c

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

lib/plugins/aws/provider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,9 +1625,10 @@ class AwsProvider {
16251625
return customRole['Fn::GetAtt'][0];
16261626
}
16271627
if (
1628-
// otherwise, check if we have an import or parameters ref
1628+
// otherwise, check if we have an import, parameters ref or sub
16291629
customRole['Fn::ImportValue'] ||
1630-
customRole.Ref
1630+
customRole.Ref ||
1631+
customRole['Fn::Sub']
16311632
) {
16321633
return null;
16331634
}

test/unit/lib/plugins/aws/package/compile/events/sqs.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,4 +643,36 @@ describe('AwsCompileSQSEvents #2', () => {
643643
expect(eventSourceMappingResource.Properties.MaximumBatchingWindowInSeconds).to.equal(100);
644644
});
645645
});
646+
647+
it('should not depend on default IAM role when custom role defined', async () => {
648+
const { awsNaming, cfTemplate } = await runServerless({
649+
fixture: 'function',
650+
configExt: {
651+
provider: {
652+
iam: {
653+
role: {
654+
'Fn::Sub': 'arn:aws:iam::${AWS::AccountId}:role/iam-role-name',
655+
},
656+
},
657+
},
658+
functions: {
659+
foo: {
660+
events: [
661+
{
662+
sqs: {
663+
arn: 'arn:aws:sqs:region:account:MyQueue',
664+
},
665+
},
666+
],
667+
},
668+
},
669+
},
670+
command: 'package',
671+
});
672+
673+
const queueLogicalId = awsNaming.getQueueLogicalId('foo', 'MyQueue');
674+
const eventSourceMappingResource = cfTemplate.Resources[queueLogicalId];
675+
676+
expect(eventSourceMappingResource.DependsOn).to.deep.equal([]);
677+
});
646678
});

0 commit comments

Comments
 (0)