From 8937cac78e7be0fa8ff6969c28d12de58aed4ba3 Mon Sep 17 00:00:00 2001 From: Mithun Kamath Date: Mon, 12 Dec 2022 18:42:50 +0530 Subject: [PATCH] #5 fix issue where fetching params from SSM would result in ThrottlingException(s) --- codealike.json | 1 + package-lock.json | 4 ++-- src/lib/awsManager.js | 11 ++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 codealike.json diff --git a/codealike.json b/codealike.json new file mode 100644 index 0000000..de6558a --- /dev/null +++ b/codealike.json @@ -0,0 +1 @@ +{"projectId":"0bf825e0-7a14-11ed-9fab-c79574c4e560","projectName":"config-wrapper"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 68fa771..5fed9b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@opentorc/config-wrapper", - "version": "1.2.0", + "version": "1.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@opentorc/config-wrapper", - "version": "1.2.0", + "version": "1.2.2", "license": "ISC", "dependencies": { "arg": "^5.0.1", diff --git a/src/lib/awsManager.js b/src/lib/awsManager.js index 6bc80e0..093eb9b 100644 --- a/src/lib/awsManager.js +++ b/src/lib/awsManager.js @@ -4,6 +4,8 @@ let ssm const BASE_PATH = '/torc' +const cachedParams = {} + function initializeSSM() { if (!ssm) { ssm = new AWS.SSM(); @@ -44,6 +46,12 @@ async function getParameter(env, service, paramName, isEncrypted) { async function getParametersByService(env, service, isEncrypted) { const Path = constructParamPath(env, service) console.log(`Getting parameters from ${Path}`) + + if (cachedParams[Path]) { + console.log('Found parameters in cache. Returning...') + return cachedParams[Path] + } + var config = { Path, Recursive: true, @@ -63,11 +71,12 @@ async function getParametersByService(env, service, isEncrypted) { convertedParams[param.name] = param } - params = await ssm.getParametersByPath(config).promise() nextToken = params.NextToken config.NextToken = nextToken } while (nextToken) + cachedParams[Path] = convertedParams + return convertedParams }