diff --git a/README.md b/README.md index 3f63130..9e9506e 100644 --- a/README.md +++ b/README.md @@ -304,7 +304,7 @@ contains its entire configuration (VPC settings, environment, etc.) ## For developers ### Lifecycle events -_currently the exposed hooks are disabled after the change to the new SLS lifecycle model_ +_currently the exposed hooks are not available after the change to the new SLS lifecycle model_ The plugin adds the following lifecycle events that can be hooked by other plugins: @@ -341,6 +341,11 @@ and _serverless.service.provider.deployedAliasTemplates[]_. ## Version history +* 1.2.0 + * Fix issue when stage is specified as Serverless variable [#45](https://github.com/HyperBrain/serverless-aws-alias/issues/45) + * Add support for SNS Lambda subscriptions [#43](https://github.com/HyperBrain/serverless-aws-alias/issues/43) + * Add support for custom authorizers [#22](https://github.com/HyperBrain/serverless-aws-alias/issues/22) + * 1.1.0 * Use stage variable in APIG [#40](https://github.com/HyperBrain/serverless-aws-alias/issues/40) * Fix tail logging [#42](https://github.com/HyperBrain/serverless-aws-alias/issues/42) diff --git a/lib/stackops/apiGateway.js b/lib/stackops/apiGateway.js index a8ab3a7..64c7431 100644 --- a/lib/stackops/apiGateway.js +++ b/lib/stackops/apiGateway.js @@ -8,6 +8,7 @@ const _ = require('lodash'); const BbPromise = require('bluebird'); +const utils = require('../utils'); module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStackTemplate) { const stackName = this._provider.naming.getStackName(); @@ -142,7 +143,25 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac delete userResources.Resources[name]; } - stageStack.Resources[name] = authorizer; + const aliasedName = `${name}${this._alias}`; + const authorizerRefs = utils.findReferences(stageStack.Resources, name); + _.forEach(authorizerRefs, ref => { + _.set(stageStack.Resources, ref, { Ref: aliasedName }); + }); + + // Replace dependencies + _.forOwn(stageStack.Resources, resource => { + if (_.isString(resource.DependsOn) && resource.DependsOn === name) { + resource.DependsOn = aliasedName; + } else if (_.isArray(resource.DependsOn) && _.includes(resource.DependsOn, name)) { + _.pull(resource.DependsOn, name); + resource.DependsOn.push(aliasedName); + } + }); + + // Rename authorizer to be unique per alias + stageStack.Resources[aliasedName] = authorizer; + delete stageStack.Resources[name]; }); // Adjust permission to reference the function aliases diff --git a/package.json b/package.json index 4f96e42..a6d5a70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-aws-alias", - "version": "1.1.0", + "version": "1.2.0", "description": "Serverless plugin to support AWS function aliases", "main": "index.js", "repository": {