@@ -8,19 +8,27 @@ const { getArnPartition } = require('../../utils/arn');
88
99const logger = require ( '../../utils/logger' ) ;
1010
11- function getTaskStates ( states ) {
11+ function getTaskStates ( states , stateMachineName ) {
1212 return _ . flatMap ( states , ( state ) => {
1313 switch ( state . Type ) {
1414 case 'Task' : {
1515 return [ state ] ;
1616 }
1717 case 'Parallel' : {
1818 const parallelStates = _ . flatMap ( state . Branches , branch => _ . values ( branch . States ) ) ;
19- return getTaskStates ( parallelStates ) ;
19+ return getTaskStates ( parallelStates , stateMachineName ) ;
2020 }
2121 case 'Map' : {
2222 const mapStates = state . ItemProcessor ? state . ItemProcessor . States : state . Iterator . States ;
23- return getTaskStates ( mapStates ) ;
23+ const taskStates = getTaskStates ( mapStates , stateMachineName ) ;
24+ if ( state . ItemProcessor && state . ItemProcessor . ProcessorConfig . Mode === 'DISTRIBUTED' ) {
25+ taskStates . push ( {
26+ Resource : 'arn:aws:states:::states:startExecution' ,
27+ Mode : 'DISTRIBUTED' ,
28+ StateMachineName : stateMachineName ,
29+ } ) ;
30+ }
31+ return taskStates ;
2432 }
2533 default : {
2634 return [ ] ;
@@ -299,9 +307,16 @@ function getLambdaPermissions(state) {
299307}
300308
301309function getStepFunctionsPermissions ( state ) {
302- const stateMachineArn = state . Parameters [ 'StateMachineArn.$' ]
303- ? '*'
304- : state . Parameters . StateMachineArn ;
310+ let stateMachineArn = state . Mode === 'DISTRIBUTED' ? {
311+ 'Fn::Sub' : [
312+ `arn:aws:states:\${AWS::Region}:\${AWS::AccountId}:stateMachine:${ state . StateMachineName } ` ,
313+ ] ,
314+ } : null ;
315+
316+ if ( ! stateMachineArn ) {
317+ stateMachineArn = state . Parameters [ 'StateMachineArn.$' ] ? '*'
318+ : state . Parameters . StateMachineArn ;
319+ }
305320
306321 return [ {
307322 action : 'states:StartExecution' ,
@@ -575,7 +590,7 @@ module.exports = {
575590 throw new Error ( `Missing "definition" for state machine ${ stateMachineName } ` ) ;
576591 }
577592
578- const taskStates = getTaskStates ( stateMachineObj . definition . States ) ;
593+ const taskStates = getTaskStates ( stateMachineObj . definition . States , stateMachineName ) ;
579594 let iamPermissions = getIamPermissions . bind ( this ) ( taskStates ) ;
580595
581596 if ( stateMachineObj . loggingConfig ) {
0 commit comments