@@ -1259,4 +1259,66 @@ describe('#compileIamRole', () => {
12591259 ] ;
12601260 expect ( lambdaPermissions [ 0 ] . Resource ) . to . deep . eq ( lambdaArns ) ;
12611261 } ) ;
1262+
1263+ it ( 'should support local function names' , ( ) => {
1264+ const getStateMachine = ( name , functionName ) => ( {
1265+ name,
1266+ definition : {
1267+ StartAt : 'A' ,
1268+ States : {
1269+ A : {
1270+ Type : 'Task' ,
1271+ Resource : 'arn:aws:states:::lambda:invoke' ,
1272+ Parameters : {
1273+ FunctionName : functionName ,
1274+ Payload : {
1275+ 'ExecutionName.$' : '$$.Execution.Name' ,
1276+ } ,
1277+ } ,
1278+ End : true ,
1279+ } ,
1280+ } ,
1281+ } ,
1282+ } ) ;
1283+
1284+ const lambda1 = { Ref : 'hello-world' } ;
1285+ const lambda2 = { 'Fn::GetAtt' : [ 'hello-world' , 'Arn' ] } ;
1286+
1287+ serverless . functions = {
1288+ 'hello-world' : {
1289+ handler : 'hello-world.handler' ,
1290+ } ,
1291+ } ;
1292+
1293+ serverless . service . stepFunctions = {
1294+ stateMachines : {
1295+ myStateMachine1 : getStateMachine ( 'sm1' , lambda1 ) ,
1296+ myStateMachine2 : getStateMachine ( 'sm2' , lambda2 ) ,
1297+ } ,
1298+ } ;
1299+
1300+ serverlessStepFunctions . compileIamRole ( ) ;
1301+ const statements = serverlessStepFunctions . serverless . service
1302+ . provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
1303+ . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
1304+
1305+ const lambdaPermissions = statements . filter ( s => _ . isEqual ( s . Action , [ 'lambda:InvokeFunction' ] ) ) ;
1306+ expect ( lambdaPermissions ) . to . have . lengthOf ( 1 ) ;
1307+
1308+ const lambdaArns = [
1309+ {
1310+ 'Fn::Sub' : [
1311+ 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${FunctionName}' ,
1312+ { FunctionName : { Ref : 'HelloDashworldLambdaFunction' } } ,
1313+ ] ,
1314+ } ,
1315+ {
1316+ 'Fn::GetAtt' : [
1317+ 'HelloDashworldLambdaFunction' ,
1318+ 'Arn' ,
1319+ ] ,
1320+ } ,
1321+ ] ;
1322+ expect ( lambdaPermissions [ 0 ] . Resource ) . to . deep . eq ( lambdaArns ) ;
1323+ } ) ;
12621324} ) ;
0 commit comments