Skip to content

Commit

Permalink
CR Changes: fix the case of per-function custom Role
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergii Kovalev authored and Aleksander Dikanski committed May 10, 2019
1 parent b6d106d commit 162f371
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/stackops/lambdaRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac

// Replace references
const functions = _.filter(stageStack.Resources, ['Type', 'AWS::Lambda::Function']);
_.forEach(functions, func => {
if (_.isEqual(func.Properties.Role, { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn' ]})) {
func.Properties.Role = {
'Fn::GetAtt': [
roleLogicalId,
'Arn'
]
};
const dependencyIndex = _.indexOf(func.DependsOn, 'IamRoleLambdaExecution');
func.DependsOn[dependencyIndex] = roleLogicalId;
}

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

_.forEach(functionsWithIamRoleReference, func => {
func.Properties.Role = {
'Fn::GetAtt': [
roleLogicalId,
'Arn'
]
};
const dependencyIndex = _.indexOf(func.DependsOn, 'IamRoleLambdaExecution');
func.DependsOn[dependencyIndex] = roleLogicalId;
});

if (_.has(currentTemplate, 'Resources.IamRoleLambdaExecution')) {
Expand Down

0 comments on commit 162f371

Please sign in to comment.