Skip to content

Commit

Permalink
#5 fix issue where fetching params from SSM would result in Throttlin…
Browse files Browse the repository at this point in the history
…gException(s)
  • Loading branch information
callmekatootie committed Dec 12, 2022
1 parent 49c53f8 commit 8937cac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions codealike.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"projectId":"0bf825e0-7a14-11ed-9fab-c79574c4e560","projectName":"config-wrapper"}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/lib/awsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let ssm

const BASE_PATH = '/torc'

const cachedParams = {}

function initializeSSM() {
if (!ssm) {
ssm = new AWS.SSM();
Expand Down Expand Up @@ -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,
Expand All @@ -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
}

Expand Down

0 comments on commit 8937cac

Please sign in to comment.