Skip to content

Commit 73cc27b

Browse files
committed
fix: correctly resolve lambda function name from Arguments or Parameters
1 parent 67ddb59 commit 73cc27b

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

lib/deploy/stepFunctions/compileIamRole.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ function getRedshiftDataPermissions(action, state) {
362362
function getLambdaPermissions(state) {
363363
// function name can be name-only, name-only with alias, full arn or partial arn
364364
// https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestParameters
365-
const functionName = state.Parameters.FunctionName;
365+
const functionName = getParameterOrArgument(state, 'FunctionName');
366366
if (_.isString(functionName)) {
367367
const segments = functionName.split(':');
368368

@@ -429,10 +429,11 @@ function getLambdaPermissions(state) {
429429
}];
430430
}
431431

432-
if (state.Parameters['FunctionName.$']) {
432+
if (getParameterOrArgument(state, 'FunctionName.$')) {
433+
const allowedFunctions = getParameterOrArgument(state, 'AllowedFunctions');
433434
return [{
434435
action: 'lambda:InvokeFunction',
435-
resource: state.Parameters.AllowedFunctions ? state.Parameters.AllowedFunctions : '*',
436+
resource: allowedFunctions || '*',
436437
}];
437438
}
438439

lib/deploy/stepFunctions/compileIamRole.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -3587,6 +3587,41 @@ describe('#compileIamRole', () => {
35873587
]);
35883588
});
35893589

3590+
it.only('should resolve FunctionName from the Arguments property when there is no Parameters property', () => {
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+
Arguments: {
3602+
FunctionName: 'arn:aws:lambda:us-west-2:1234567890:function:foo',
3603+
Payload: '{% $states.input.Payload %}',
3604+
},
3605+
End: true,
3606+
},
3607+
},
3608+
},
3609+
},
3610+
},
3611+
};
3612+
3613+
serverlessStepFunctions.compileIamRole();
3614+
const statements = serverlessStepFunctions.serverless.service
3615+
.provider.compiledCloudFormationTemplate.Resources.StateMachine1Role
3616+
.Properties.Policies[0].PolicyDocument.Statement;
3617+
const lambdaPermissions = statements.filter(s => _.isEqual(s.Action, ['lambda:InvokeFunction']));
3618+
expect(lambdaPermissions).to.have.lengthOf(1);
3619+
expect(lambdaPermissions[0].Resource).to.deep.equal([
3620+
'arn:aws:lambda:us-west-2:1234567890:function:foo',
3621+
'arn:aws:lambda:us-west-2:1234567890:function:foo:*',
3622+
]);
3623+
});
3624+
35903625
it('should support variable FunctionName', () => {
35913626
serverless.service.stepFunctions = {
35923627
stateMachines: {

0 commit comments

Comments
 (0)