Skip to content

Commit

Permalink
Fixes #16 Support Serverless <1.7 and upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Mar 11, 2017
1 parent 528ae1e commit 73d1880
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ and _serverless.service.provider.deployedAliasTemplates[]_.

## Version history

* 0.3.1-alpha1 Support Serverless 1.6 again with upgrade to 1.7+
* 0.3.0-alpha1 Support lambda event subscriptions
* 0.2.1-alpha1 Alias remove command removes unused resources
* 0.2.0-alpha1 Support custom resources
Expand Down
13 changes: 11 additions & 2 deletions lib/aliasRestructureStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,17 @@ module.exports = {
aliasHandleLambdaRole(currentTemplate, aliasStackTemplates) {

const stageStack = this._serverless.service.provider.compiledCloudFormationTemplate;
const stageRolePolicies = _.get(stageStack, 'Resources.IamRoleLambdaExecution.Properties.Policies', []);
const currentRolePolicies = _.get(currentTemplate, 'Resources.IamRoleLambdaExecution.Properties.Policies', []);
let stageRolePolicies = _.get(stageStack, 'Resources.IamRoleLambdaExecution.Properties.Policies', []);
let currentRolePolicies = _.get(currentTemplate, 'Resources.IamRoleLambdaExecution.Properties.Policies', []);

// Older serverless versions (<1.7.0) do not use a inline policy.
if (_.isEmpty(currentRolePolicies.length) && _.has(currentTemplate, 'Resources.IamPolicyLambdaExecution')) {
this._serverless.cli.log('WARNING: Project created with SLS < 1.7.0. Using resources from policy.');
currentRolePolicies = [ _.get(currentTemplate, 'Resources.IamPolicyLambdaExecution.Properties') ];
}
if (_.isEmpty(stageRolePolicies.length) && _.has(stageStack, 'Resources.IamPolicyLambdaExecution')) {
stageRolePolicies = [ _.get(stageStack, 'Resources.IamPolicyLambdaExecution.Properties') ];
}

// For now we only merge the first policy document and exit if SLS changes this behavior.
if (stageRolePolicies.length !== 1 || currentRolePolicies.length !== 1) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-aws-alias",
"version": "0.3.0-alpha1",
"version": "0.3.1-alpha1",
"description": "Serverless plugin to support AWS function aliases",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 73d1880

Please sign in to comment.