-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-parameters.js
37 lines (36 loc) · 1.14 KB
/
get-parameters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const AWSSSM = require('aws-sdk/clients/ssm')
const ssmClient = new AWSSSM()
module.exports = function getParameters(paths, isRecursive = false) {
return new Promise((resolve, reject) => {
let index = 0
const parameters = []
const getParametersByPath = (path, nextToken = undefined) => {
const opts = {
Path: path,
WithDecryption: true,
Recursive: isRecursive,
NextToken: nextToken,
}
ssmClient.getParametersByPath(opts, (err, data) => {
if (err) {
reject(new Error('Unable to get the parameters.'))
} else {
// If the path has more than 10 parameters then will be returned a
// token (.NextToken) to get the next 10 parameters, and so on
if (data.NextToken) {
getParametersByPath(path, data.NextToken)
} else {
parameters.push(data.Parameters)
if (index > paths.length - 1) {
index++
getParametersByPath(paths[index])
} else {
resolve(parameters)
}
}
}
})
}
getParametersByPath(paths[index])
})
}