diff --git a/README.md b/README.md index 69ada3f..bbd2fc7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/aliasRestructureStack.js b/lib/aliasRestructureStack.js index cd34944..6a8540b 100644 --- a/lib/aliasRestructureStack.js +++ b/lib/aliasRestructureStack.js @@ -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) { diff --git a/package.json b/package.json index 56113b1..c962aa8 100644 --- a/package.json +++ b/package.json @@ -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": {