From 5a48d6ba7ac5c86371d0e26b6ca3c662caab69da Mon Sep 17 00:00:00 2001 From: Frank Schmid Date: Thu, 25 May 2017 14:24:26 +0200 Subject: [PATCH] Use stage variable to set alias --- README.md | 8 ++++++-- lib/stackops/apiGateway.js | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0da236..e24e136 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,12 @@ as name. The created API Gateway stage has the stage variables SERVERLESS_STAGE and SERVERLESS_ALIAS set to the corresponding values. -Upcoming: There will be a configuration possibility to configure the APIG -stage parameters separately soon. +If you want to test your APIG endpoints in the AWS ApiGateway console, you have +to set the SERVERLESS_ALIAS stage variable to the alias that will be used for the +Lambda invocation. This will call the aliased function version. + +Deployed stages have the alias stage variable set fixed, so a deployed alias stage is +hard-wired to the aliased Lambda versions. ## Reference the current alias in your service diff --git a/lib/stackops/apiGateway.js b/lib/stackops/apiGateway.js index f95c366..fd8deb6 100644 --- a/lib/stackops/apiGateway.js +++ b/lib/stackops/apiGateway.js @@ -114,7 +114,8 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac const uriParts = method.Properties.Integration.Uri['Fn::Join'][1]; const funcIndex = _.findIndex(uriParts, part => _.has(part, 'Fn::GetAtt')); - uriParts.splice(funcIndex + 1, 0, `:${this._alias}`); + // Use the SERVERLESS_ALIAS stage variable to determine the called function alias + uriParts.splice(funcIndex + 1, 0, ':${stageVariables.SERVERLESS_ALIAS}'); } // Check for user resource overrides