@@ -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- const taskStates = getTaskStates ( mapStates ) ;
23+ const taskStates = getTaskStates ( mapStates , stateMachineName ) ;
24+ if ( state . ItemProcessor && state . ItemProcessor . ProcessorConfig
25+ && state . ItemProcessor . ProcessorConfig . Mode === 'DISTRIBUTED' ) {
26+ taskStates . push ( {
27+ Resource : 'arn:aws:states:::states:startExecution' ,
28+ Mode : 'DISTRIBUTED' ,
29+ StateMachineName : stateMachineName ,
30+ } ) ;
31+ }
2432 if ( state . ItemReader ) {
2533 taskStates . push ( state . ItemReader ) ;
2634 }
@@ -303,9 +311,16 @@ function getLambdaPermissions(state) {
303311}
304312
305313function getStepFunctionsPermissions ( state ) {
306- const stateMachineArn = state . Parameters [ 'StateMachineArn.$' ]
307- ? '*'
308- : state . Parameters . StateMachineArn ;
314+ let stateMachineArn = state . Mode === 'DISTRIBUTED' ? {
315+ 'Fn::Sub' : [
316+ `arn:aws:states:\${AWS::Region}:\${AWS::AccountId}:stateMachine:${ state . StateMachineName } ` ,
317+ ] ,
318+ } : null ;
319+
320+ if ( ! stateMachineArn ) {
321+ stateMachineArn = state . Parameters [ 'StateMachineArn.$' ] ? '*'
322+ : state . Parameters . StateMachineArn ;
323+ }
309324
310325 return [ {
311326 action : 'states:StartExecution' ,
@@ -591,7 +606,7 @@ module.exports = {
591606 throw new Error ( `Missing "definition" for state machine ${ stateMachineName } ` ) ;
592607 }
593608
594- const taskStates = getTaskStates ( stateMachineObj . definition . States ) ;
609+ const taskStates = getTaskStates ( stateMachineObj . definition . States , stateMachineName ) ;
595610 let iamPermissions = getIamPermissions . bind ( this ) ( taskStates ) ;
596611
597612 if ( stateMachineObj . loggingConfig ) {
0 commit comments