@@ -3587,7 +3587,49 @@ describe('#compileIamRole', () => {
3587
3587
] ) ;
3588
3588
} ) ;
3589
3589
3590
- it ( 'should support variable FunctionName' , ( ) => {
3590
+ itParam ( 'should resolve FunctionName: ${value}' , [ 'JSONPath' , 'JSONata' ] , ( queryLanguage ) => {
3591
+ serverless . service . stepFunctions = {
3592
+ stateMachines : {
3593
+ myStateMachine1 : {
3594
+ id : 'StateMachine1' ,
3595
+ definition : {
3596
+ StartAt : 'A' ,
3597
+ States : {
3598
+ A : {
3599
+ Type : 'Task' ,
3600
+ Resource : 'arn:aws:states:::lambda:invoke' ,
3601
+ ...getParamsOrArgs (
3602
+ queryLanguage ,
3603
+ {
3604
+ FunctionName : 'arn:aws:lambda:us-west-2:1234567890:function:foo' ,
3605
+ 'Payload.$' : '$.Payload' ,
3606
+ } ,
3607
+ {
3608
+ FunctionName : 'arn:aws:lambda:us-west-2:1234567890:function:foo' ,
3609
+ Payload : '{% $states.input.Payload %}' ,
3610
+ } ,
3611
+ ) ,
3612
+ End : true ,
3613
+ } ,
3614
+ } ,
3615
+ } ,
3616
+ } ,
3617
+ } ,
3618
+ } ;
3619
+
3620
+ serverlessStepFunctions . compileIamRole ( ) ;
3621
+ const statements = serverlessStepFunctions . serverless . service
3622
+ . provider . compiledCloudFormationTemplate . Resources . StateMachine1Role
3623
+ . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
3624
+ const lambdaPermissions = statements . filter ( s => _ . isEqual ( s . Action , [ 'lambda:InvokeFunction' ] ) ) ;
3625
+ expect ( lambdaPermissions ) . to . have . lengthOf ( 1 ) ;
3626
+ expect ( lambdaPermissions [ 0 ] . Resource ) . to . deep . equal ( [
3627
+ 'arn:aws:lambda:us-west-2:1234567890:function:foo' ,
3628
+ 'arn:aws:lambda:us-west-2:1234567890:function:foo:*' ,
3629
+ ] ) ;
3630
+ } ) ;
3631
+
3632
+ itParam ( 'should support variable FunctionName: ${value}' , [ 'JSONPath' , 'JSONata' ] , ( queryLanguage ) => {
3591
3633
serverless . service . stepFunctions = {
3592
3634
stateMachines : {
3593
3635
myStateMachine1 : {
@@ -3598,26 +3640,47 @@ describe('#compileIamRole', () => {
3598
3640
A : {
3599
3641
Type : 'Task' ,
3600
3642
Resource : 'arn:aws:states:::lambda:invoke.waitForTaskToken' ,
3601
- Parameters : {
3602
- 'FunctionName.$' : '$.functionName' ,
3603
- Payload : {
3604
- 'model.$' : '$.new_model' ,
3605
- 'token.$' : '$$.Task.Token' ,
3643
+ ...getParamsOrArgs (
3644
+ queryLanguage ,
3645
+ {
3646
+ 'FunctionName.$' : '$.functionName' ,
3647
+ Payload : {
3648
+ 'model.$' : '$.new_model' ,
3649
+ 'token.$' : '$$.Task.Token' ,
3650
+ } ,
3606
3651
} ,
3607
- } ,
3652
+ {
3653
+ FunctionName : '{% $states.input.functionName %}' ,
3654
+ Payload : {
3655
+ model : '{% $states.input.new_model %}' ,
3656
+ token : '{% $states.context.Task.Token %}' ,
3657
+ } ,
3658
+ } ,
3659
+ ) ,
3608
3660
Next : 'B' ,
3609
3661
} ,
3610
3662
B : {
3611
3663
Type : 'Task' ,
3612
3664
Resource : 'arn:aws:states:::lambda:invoke.waitForTaskToken' ,
3613
- Parameters : {
3614
- 'FunctionName.$' : '$.functionName' ,
3615
- AllowedFunctions : '*limited*' ,
3616
- Payload : {
3617
- 'model.$' : '$.new_model' ,
3618
- 'token.$' : '$$.Task.Token' ,
3665
+ ...getParamsOrArgs (
3666
+ queryLanguage ,
3667
+ {
3668
+ 'FunctionName.$' : '$.functionName' ,
3669
+ AllowedFunctions : '*limited*' ,
3670
+ Payload : {
3671
+ 'model.$' : '$.new_model' ,
3672
+ 'token.$' : '$$.Task.Token' ,
3673
+ } ,
3619
3674
} ,
3620
- } ,
3675
+ {
3676
+ FunctionName : '{% $states.input.functionName %}' ,
3677
+ AllowedFunctions : '*limited*' ,
3678
+ Payload : {
3679
+ model : '{% $states.input.new_model %}' ,
3680
+ token : '{% $states.context.Task.Token %}' ,
3681
+ } ,
3682
+ } ,
3683
+ ) ,
3621
3684
End : true ,
3622
3685
} ,
3623
3686
} ,
@@ -3643,27 +3706,49 @@ describe('#compileIamRole', () => {
3643
3706
A : {
3644
3707
Type : 'Task' ,
3645
3708
Resource : 'arn:aws:states:::lambda:invoke.waitForTaskToken' ,
3646
- Parameters : {
3647
- 'FunctionName.$' : '$.functionName' ,
3648
- AllowedFunctions : 'arn:aws:lambda:us-west-2:1234567890:function:foo' ,
3649
- Payload : {
3650
- 'model.$' : '$.new_model' ,
3651
- 'token.$' : '$$.Task.Token' ,
3709
+ ...getParamsOrArgs (
3710
+ queryLanguage ,
3711
+ {
3712
+ 'FunctionName.$' : '$.functionName' ,
3713
+ AllowedFunctions : 'arn:aws:lambda:us-west-2:1234567890:function:foo' ,
3714
+ Payload : {
3715
+ 'model.$' : '$.new_model' ,
3716
+ 'token.$' : '$$.Task.Token' ,
3717
+ } ,
3652
3718
} ,
3653
- } ,
3719
+ {
3720
+ FunctionName : '{% $states.input.functionName %}' ,
3721
+ AllowedFunctions : 'arn:aws:lambda:us-west-2:1234567890:function:foo' ,
3722
+ Payload : {
3723
+ model : '{% $states.input.new_model %}' ,
3724
+ token : '{% $states.context.Task.Token %}' ,
3725
+ } ,
3726
+ } ,
3727
+ ) ,
3654
3728
Next : 'B' ,
3655
3729
} ,
3656
3730
B : {
3657
3731
Type : 'Task' ,
3658
3732
Resource : 'arn:aws:states:::lambda:invoke.waitForTaskToken' ,
3659
- Parameters : {
3660
- 'FunctionName.$' : '$.functionName' ,
3661
- AllowedFunctions : '*limited*' ,
3662
- Payload : {
3663
- 'model.$' : '$.new_model' ,
3664
- 'token.$' : '$$.Task.Token' ,
3733
+ ...getParamsOrArgs (
3734
+ queryLanguage ,
3735
+ {
3736
+ 'FunctionName.$' : '$.functionName' ,
3737
+ AllowedFunctions : '*limited*' ,
3738
+ Payload : {
3739
+ 'model.$' : '$.new_model' ,
3740
+ 'token.$' : '$$.Task.Token' ,
3741
+ } ,
3665
3742
} ,
3666
- } ,
3743
+ {
3744
+ FunctionName : '{% $states.input.functionName %}' ,
3745
+ AllowedFunctions : '*limited*' ,
3746
+ Payload : {
3747
+ model : '{% $states.input.new_model %}' ,
3748
+ token : '{% $states.context.Task.Token %}' ,
3749
+ } ,
3750
+ } ,
3751
+ ) ,
3667
3752
End : true ,
3668
3753
} ,
3669
3754
} ,
0 commit comments