Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/deploy/stepFunctions/compileIamRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function getRedshiftDataPermissions(action, state) {
function getLambdaPermissions(state) {
// function name can be name-only, name-only with alias, full arn or partial arn
// https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestParameters
const functionName = state.Parameters.FunctionName;
const functionName = getParameterOrArgument(state, 'FunctionName');
if (_.isString(functionName)) {
const segments = functionName.split(':');

Expand Down Expand Up @@ -429,10 +429,11 @@ function getLambdaPermissions(state) {
}];
}

if (state.Parameters['FunctionName.$']) {
if (getParameterOrArgument(state, 'FunctionName.$')) {
const allowedFunctions = getParameterOrArgument(state, 'AllowedFunctions');
return [{
action: 'lambda:InvokeFunction',
resource: state.Parameters.AllowedFunctions ? state.Parameters.AllowedFunctions : '*',
resource: allowedFunctions || '*',
}];
}

Expand Down
35 changes: 35 additions & 0 deletions lib/deploy/stepFunctions/compileIamRole.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3587,6 +3587,41 @@ describe('#compileIamRole', () => {
]);
});

it('should resolve FunctionName from the Arguments property when there is no Parameters property', () => {
serverless.service.stepFunctions = {
stateMachines: {
myStateMachine1: {
id: 'StateMachine1',
definition: {
StartAt: 'A',
States: {
A: {
Type: 'Task',
Resource: 'arn:aws:states:::lambda:invoke',
Arguments: {
FunctionName: 'arn:aws:lambda:us-west-2:1234567890:function:foo',
Payload: '{% $states.input.Payload %}',
},
End: true,
},
},
},
},
},
};

serverlessStepFunctions.compileIamRole();
const statements = serverlessStepFunctions.serverless.service
.provider.compiledCloudFormationTemplate.Resources.StateMachine1Role
.Properties.Policies[0].PolicyDocument.Statement;
const lambdaPermissions = statements.filter(s => _.isEqual(s.Action, ['lambda:InvokeFunction']));
expect(lambdaPermissions).to.have.lengthOf(1);
expect(lambdaPermissions[0].Resource).to.deep.equal([
'arn:aws:lambda:us-west-2:1234567890:function:foo',
'arn:aws:lambda:us-west-2:1234567890:function:foo:*',
]);
});

it('should support variable FunctionName', () => {
serverless.service.stepFunctions = {
stateMachines: {
Expand Down