@@ -22,6 +22,7 @@ module.exports = {
2222 let Description ;
2323 let Name ;
2424 let EventBusName ;
25+ let IamRole ;
2526
2627 if ( typeof eventRule === 'object' ) {
2728 if ( ! eventRule . event ) {
@@ -43,6 +44,7 @@ module.exports = {
4344 Description = eventRule . description ;
4445 Name = eventRule . name ;
4546 EventBusName = eventRule . eventBusName ;
47+ IamRole = eventRule . iamRole ;
4648
4749 if ( Input && InputPath ) {
4850 const errorMessage = [
@@ -92,12 +94,12 @@ module.exports = {
9294 ${ InputPath ? `"InputPath": "${ InputPath . replace ( / \r ? \n / g, '' ) } ",` : '' }
9395 "Arn": { "Ref": "${ stateMachineLogicalId } " },
9496 "Id": "${ cloudWatchId } ",
95- "RoleArn": {
97+ ${ IamRole ? `"RoleArn":" ${ IamRole } "` : ` "RoleArn": {
9698 "Fn::GetAtt": [
9799 "${ cloudWatchIamRoleLogicalId } ",
98100 "Arn"
99101 ]
100- }
102+ }` }
101103 }]
102104 }
103105 }
@@ -146,12 +148,17 @@ module.exports = {
146148 [ cloudWatchLogicalId ] : JSON . parse ( cloudWatchEventRuleTemplate ) ,
147149 } ;
148150
149- const newPermissionObject = {
150- [ cloudWatchIamRoleLogicalId ] : JSON . parse ( iamRoleTemplate ) ,
151- } ;
151+ const objectsToMerge = [ newCloudWatchEventRuleObject ]
152+
153+ if ( ! IamRole ) {
154+ const newPermissionObject = {
155+ [ cloudWatchIamRoleLogicalId ] : JSON . parse ( iamRoleTemplate ) ,
156+ } ;
157+
158+ objectsToMerge . push ( newPermissionObject )
159+ }
152160
153- _ . merge ( this . serverless . service . provider . compiledCloudFormationTemplate . Resources ,
154- newCloudWatchEventRuleObject , newPermissionObject ) ;
161+ _ . merge ( this . serverless . service . provider . compiledCloudFormationTemplate . Resources , ...objectsToMerge ) ;
155162 }
156163 } ) ;
157164 }
0 commit comments