Skip to content

Commit

Permalink
fix(pull): paginate GetParametersByPath command
Browse files Browse the repository at this point in the history
Paginate GetParametersByPath command because single reguest can obtain only up to 10 items.
  • Loading branch information
poikaa committed Oct 6, 2021
1 parent e129bf3 commit b8d3824
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/ssm.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SSMClient, GetParametersByPathCommand, PutParameterCommand, ParameterType } from '@aws-sdk/client-ssm'
import { SSMClient, paginateGetParametersByPath, PutParameterCommand, ParameterType } from '@aws-sdk/client-ssm'
import { parseDotenv } from './dotenv.mjs'

function createClient({ region, accessKeyId, secretAccessKey }) {
Expand All @@ -14,16 +14,21 @@ function createClient({ region, accessKeyId, secretAccessKey }) {
}

export async function pullParameters({ prefix, ...config }) {
const client = createClient(config)

const command = new GetParametersByPathCommand({
Path: prefix,
Recursive: true,
WithDecryption: true,
})
const paginator = paginateGetParametersByPath(
{
client: createClient(config),
},
{
Path: prefix,
Recursive: true,
WithDecryption: true,
}
)

const { Parameters } = await client.send(command)
const parameterList = Parameters ?? []
const parameterList = []
for await (const page of paginator) {
parameterList.push(...page.Parameters)
}

return parameterList.reduce(
(parameters, { Name, Value }) => ({
Expand Down

0 comments on commit b8d3824

Please sign in to comment.