Skip to content

Commit

Permalink
Merge pull request #157 from Enase/fix-per-function-role
Browse files Browse the repository at this point in the history
Tests for - fix the case of per-function custom Role
  • Loading branch information
Enase authored May 10, 2019
2 parents dd1dbba + cdff2ce commit e12d157
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/stackops/lambdaRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
const role = stageStack.Resources.IamRoleLambdaExecution;

// Set role name
_.last(role.Properties.RoleName['Fn::Join']).push(this._alias);
if (role.Properties.RoleName['Fn::Join']) {
_.last(role.Properties.RoleName['Fn::Join']).push(this._alias);
}

stageStack.Resources[roleLogicalId] = stageStack.Resources.IamRoleLambdaExecution;
delete stageStack.Resources.IamRoleLambdaExecution;

// Replace references
const functions = _.filter(stageStack.Resources, ['Type', 'AWS::Lambda::Function']);
_.forEach(functions, func => {

const functionsWithIamRoleReference = _.filter(functions, (func) => _.isEqual(
func.Properties.Role,
{'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn' ]}
));

_.forEach(functionsWithIamRoleReference, func => {
func.Properties.Role = {
'Fn::GetAtt': [
roleLogicalId,
Expand Down
Loading

0 comments on commit e12d157

Please sign in to comment.