@@ -777,4 +777,75 @@ describe('#compileStateMachines', () => {
777777 const refParam = params [ functionParam ] ;
778778 expect ( refParam ) . to . eql ( { 'Fn::GetAtt' : [ 'HelloDashworldLambdaFunction' , 'Arn' ] } ) ;
779779 } ) ;
780+
781+ it ( 'should support local function names for lambda::invoke resource type' , ( ) => {
782+ serverless . service . functions = {
783+ 'hello-world' : {
784+ handler : 'hello-world.handler' ,
785+ } ,
786+ } ;
787+ serverless . service . stepFunctions = {
788+ stateMachines : {
789+ myStateMachine1 : {
790+ id : 'Test' ,
791+ definition : {
792+ StartAt : 'Lambda1' ,
793+ States : {
794+ Lambda1 : {
795+ Type : 'Task' ,
796+ Resource : 'arn:aws:states:::lambda:invoke' ,
797+ Parameters : {
798+ FunctionName : {
799+ Ref : 'hello-world' ,
800+ } ,
801+ Payload : {
802+ 'ExecutionName.$' : '$$.Execution.Name' ,
803+ } ,
804+ } ,
805+ Next : 'Lambda2' ,
806+ } ,
807+ Lambda2 : {
808+ Type : 'Task' ,
809+ Resource : 'arn:aws:states:::lambda:invoke' ,
810+ Parameters : {
811+ FunctionName : {
812+ 'Fn::GetAtt' : [ 'hello-world' , 'Arn' ] ,
813+ } ,
814+ Payload : {
815+ 'ExecutionName.$' : '$$.Execution.Name' ,
816+ } ,
817+ } ,
818+ End : true ,
819+ } ,
820+ } ,
821+ } ,
822+ } ,
823+ } ,
824+ } ;
825+
826+ serverlessStepFunctions . compileStateMachines ( ) ;
827+ const stateMachine = serverlessStepFunctions . serverless . service
828+ . provider . compiledCloudFormationTemplate . Resources
829+ . Test ;
830+
831+ expect ( stateMachine . Properties . DefinitionString ) . to . haveOwnProperty ( 'Fn::Sub' ) ;
832+ expect ( stateMachine . Properties . DefinitionString [ 'Fn::Sub' ] ) . to . have . lengthOf ( 2 ) ;
833+
834+ const [ json , params ] = stateMachine . Properties . DefinitionString [ 'Fn::Sub' ] ;
835+ const modifiedDefinition = JSON . parse ( json ) ;
836+
837+ const lambda1 = modifiedDefinition . States . Lambda1 ;
838+ expect ( lambda1 . Parameters . FunctionName . startsWith ( '${' ) ) . to . eq ( true ) ;
839+ const lambda1ParamName = lambda1 . Parameters . FunctionName . replace ( / [ $ { } ] / g, '' ) ;
840+ expect ( params ) . to . haveOwnProperty ( lambda1ParamName ) ;
841+ const lambda1Param = params [ lambda1ParamName ] ;
842+ expect ( lambda1Param ) . to . eql ( { Ref : 'HelloDashworldLambdaFunction' } ) ;
843+
844+ const lambda2 = modifiedDefinition . States . Lambda2 ;
845+ expect ( lambda2 . Parameters . FunctionName . startsWith ( '${' ) ) . to . eq ( true ) ;
846+ const lambda2ParamName = lambda2 . Parameters . FunctionName . replace ( / [ $ { } ] / g, '' ) ;
847+ expect ( params ) . to . haveOwnProperty ( lambda2ParamName ) ;
848+ const lambda2Param = params [ lambda2ParamName ] ;
849+ expect ( lambda2Param ) . to . eql ( { 'Fn::GetAtt' : [ 'HelloDashworldLambdaFunction' , 'Arn' ] } ) ;
850+ } ) ;
780851} ) ;
0 commit comments