File tree 2 files changed +56
-4
lines changed
2 files changed +56
-4
lines changed Original file line number Diff line number Diff line change @@ -614,14 +614,15 @@ module.exports = {
614
614
logger . config ( this . serverless , this . v3Api ) ;
615
615
const service = this . serverless . service ;
616
616
const permissionsBoundary = service . provider . rolePermissionsBoundary ;
617
- this . getAllStateMachines ( ) . forEach ( ( stateMachineName ) => {
618
- const stateMachineObj = this . getStateMachine ( stateMachineName ) ;
617
+ this . getAllStateMachines ( ) . forEach ( ( stateMachineId ) => {
618
+ const stateMachineObj = this . getStateMachine ( stateMachineId ) ;
619
+ const stateMachineName = stateMachineObj . name || stateMachineId ;
619
620
if ( stateMachineObj . role ) {
620
621
return ;
621
622
}
622
623
623
624
if ( ! stateMachineObj . definition ) {
624
- throw new Error ( `Missing "definition" for state machine ${ stateMachineName } ` ) ;
625
+ throw new Error ( `Missing "definition" for state machine ${ stateMachineId } ` ) ;
625
626
}
626
627
627
628
const taskStates = getTaskStates ( stateMachineObj . definition . States , stateMachineName ) ;
@@ -663,7 +664,7 @@ module.exports = {
663
664
}
664
665
665
666
const stateMachineLogicalId = this . getStateMachineLogicalId (
666
- stateMachineName ,
667
+ stateMachineId ,
667
668
stateMachineObj ,
668
669
) ;
669
670
const iamRoleStateMachineLogicalId = `${ stateMachineLogicalId } Role` ;
Original file line number Diff line number Diff line change @@ -2474,6 +2474,57 @@ describe('#compileIamRole', () => {
2474
2474
] ) ;
2475
2475
} ) ;
2476
2476
2477
+ it ( 'should support custom state machine names in a Distributed Map' , ( ) => {
2478
+ const getStateMachine = ( id , lambdaArn ) => ( {
2479
+ id,
2480
+ name : 'DistributedMapper' ,
2481
+ definition : {
2482
+ StartAt : 'A' ,
2483
+ States : {
2484
+ A : {
2485
+ Type : 'Map' ,
2486
+ ItemProcessor : {
2487
+ ProcessorConfig : {
2488
+ Mode : 'DISTRIBUTED' ,
2489
+ } ,
2490
+ StartAt : 'B' ,
2491
+ States : {
2492
+ B : {
2493
+ Type : 'Task' ,
2494
+ Resource : lambdaArn ,
2495
+ End : true ,
2496
+ } ,
2497
+ } ,
2498
+ } ,
2499
+ End : true ,
2500
+ } ,
2501
+ } ,
2502
+ } ,
2503
+ } ) ;
2504
+
2505
+ serverless . service . stepFunctions = {
2506
+ stateMachines : {
2507
+ myStateMachine : getStateMachine ( 'StateMachine1' , 'arn:aws:lambda:us-west-2:1234567890:function:foo' ) ,
2508
+ } ,
2509
+ } ;
2510
+
2511
+ serverlessStepFunctions . compileIamRole ( ) ;
2512
+
2513
+ const statements = serverlessStepFunctions . serverless . service
2514
+ . provider . compiledCloudFormationTemplate . Resources . StateMachine1Role
2515
+ . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
2516
+
2517
+ const stepFunctionPermission = statements . filter ( s => _ . isEqual ( s . Action , [ 'states:StartExecution' ] ) ) ;
2518
+ expect ( stepFunctionPermission ) . to . have . lengthOf ( 1 ) ;
2519
+ expect ( stepFunctionPermission [ 0 ] . Resource ) . to . deep . eq ( [ {
2520
+ 'Fn::Sub' : [
2521
+ 'arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:DistributedMapper' ,
2522
+ { } ,
2523
+ ] ,
2524
+ } ,
2525
+ ] ) ;
2526
+ } ) ;
2527
+
2477
2528
it ( 'should support nested Map state type' , ( ) => {
2478
2529
const getStateMachine = ( id , lambdaArn1 , lambdaArn2 ) => ( {
2479
2530
id,
You can’t perform that action at this time.
0 commit comments