diff --git a/lib/classes/Variables.js b/lib/classes/Variables.js index 3c69a1516..7e4152528 100644 --- a/lib/classes/Variables.js +++ b/lib/classes/Variables.js @@ -23,6 +23,8 @@ class Variables { this.s3RefSyntax = RegExp(/^s3:(.+?)\/(.+)$/); this.stringRefSynax = RegExp(/('.*')|(".*")/g); this.ssmRefSyntax = RegExp(/^ssm:([a-zA-Z0-9_.\-/]+)[~]?(true|false)?/); + + this.ssmCache = {} } loadVariableSyntax() { @@ -365,10 +367,13 @@ class Variables { } getValueFromSsm(variableString) { + const cached = this.ssmCache[variableString]; + if (cached) return cached; const groups = variableString.match(this.ssmRefSyntax); const param = groups[1]; const decrypt = (groups[2] === 'true'); - return this.serverless.getProvider('aws') + + const promise = this.serverless.getProvider('aws') .request('SSM', 'getParameter', { @@ -387,6 +392,8 @@ class Variables { return BbPromise.resolve(undefined); } ); + this.ssmCache[variableString] = promise; + return promise; } getDeepValue(deepProperties, valueToPopulate) {