From 78240d3b723f224ca13b99004d4f1fd080fd5d75 Mon Sep 17 00:00:00 2001 From: Frank Schmid Date: Thu, 11 Feb 2016 14:45:02 +0100 Subject: [PATCH 1/2] Added CF output variables to project stage variables. The export can be controlled by a whitelist array within s-project.json named "resourceVars". --- lib/ServerlessProject.js | 1 + lib/actions/ResourcesDeploy.js | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ServerlessProject.js b/lib/ServerlessProject.js index 15e1089df..27ca35cee 100644 --- a/lib/ServerlessProject.js +++ b/lib/ServerlessProject.js @@ -35,6 +35,7 @@ class ServerlessProject { _this.components = {}; _this.templates = {}; _this.plugins = []; + _this.resourceVars = [ 'iamRoleArnLambda' ]; } /** diff --git a/lib/actions/ResourcesDeploy.js b/lib/actions/ResourcesDeploy.js index c543549c6..bb73dfd57 100644 --- a/lib/actions/ResourcesDeploy.js +++ b/lib/actions/ResourcesDeploy.js @@ -155,6 +155,7 @@ usage: serverless resources deploy`, let _this = this; let regionVars = _this.S.state.getMeta().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables; + let resourceVars = _this.S.state.getProject().resourceVars; return _this.S.state.getResources({ populate: true, @@ -239,11 +240,12 @@ usage: serverless resources deploy`, // Save stack name regionVars.resourcesStackName = cfStackData.StackName; - // Save IAM Role ARN for Project Lambdas + // Save allowed (exported) CF output variables for Project Lambdas for (let i = 0; i < cfStackData.Outputs.length; i++) { - if (cfStackData.Outputs[i].OutputKey === 'IamRoleArnLambda') { - regionVars.iamRoleArnLambda = cfStackData.Outputs[i].OutputValue; - } + let varName = cfStackData.Outputs[i].OutputKey.charAt(0).toLowerCase() + cfStackData.Outputs[i].OutputKey.slice(1); + if (resourceVars.indexOf(varName) !== -1) { + regionVars[varName] = cfStackData.Outputs[i].OutputValue; + } } }) .then(() => { From fa43a654bb62ad0aee850e1261a5f77de9f453db Mon Sep 17 00:00:00 2001 From: Frank Schmid Date: Thu, 11 Feb 2016 15:07:37 +0100 Subject: [PATCH 2/2] Add iamRoleArnLambda only internally and make use of lodaah lowerFirst function. --- lib/ServerlessProject.js | 2 +- lib/actions/ResourcesDeploy.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ServerlessProject.js b/lib/ServerlessProject.js index 27ca35cee..e5bb6fb8d 100644 --- a/lib/ServerlessProject.js +++ b/lib/ServerlessProject.js @@ -35,7 +35,7 @@ class ServerlessProject { _this.components = {}; _this.templates = {}; _this.plugins = []; - _this.resourceVars = [ 'iamRoleArnLambda' ]; + _this.resourceVars = []; } /** diff --git a/lib/actions/ResourcesDeploy.js b/lib/actions/ResourcesDeploy.js index bb73dfd57..2bbc0f100 100644 --- a/lib/actions/ResourcesDeploy.js +++ b/lib/actions/ResourcesDeploy.js @@ -12,6 +12,7 @@ module.exports = function(SPlugin, serverlessPath) { SError = require(path.join(serverlessPath, 'ServerlessError')), SCli = require(path.join(serverlessPath, 'utils/cli')), BbPromise = require('bluebird'), + _ = require('lodash'), SUtils = require(path.join(serverlessPath, 'utils/index')); class ResourcesDeploy extends SPlugin { @@ -155,7 +156,7 @@ usage: serverless resources deploy`, let _this = this; let regionVars = _this.S.state.getMeta().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables; - let resourceVars = _this.S.state.getProject().resourceVars; + let resourceVars = [ 'iamRoleArnLambda' ].concat( _this.S.state.getProject().resourceVars); return _this.S.state.getResources({ populate: true, @@ -242,7 +243,7 @@ usage: serverless resources deploy`, // Save allowed (exported) CF output variables for Project Lambdas for (let i = 0; i < cfStackData.Outputs.length; i++) { - let varName = cfStackData.Outputs[i].OutputKey.charAt(0).toLowerCase() + cfStackData.Outputs[i].OutputKey.slice(1); + let varName = _.lowerFirst(cfStackData.Outputs[i].OutputKey); if (resourceVars.indexOf(varName) !== -1) { regionVars[varName] = cfStackData.Outputs[i].OutputValue; }