add cache to ssm variables

This commit is contained in:
Benjamin Forster 2017-11-29 17:10:05 +11:00
parent 7730a65d50
commit de22ae698b

View File

@ -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) {