@sudolabs-io/aws-ssm-cli
Version:
Command line tool for AWS Systems Manager Parameter Store
49 lines (42 loc) • 1.09 kB
text/typescript
import _ from 'lodash'
import { SSMClient, paginateGetParametersByPath } from '@aws-sdk/client-ssm'
import { createClient } from './client'
import { ClientConfig, Parameters } from './types'
export interface Pull extends ClientConfig {
client?: SSMClient
prefix: string
}
type Parameter = {
name: string
value: string
}
export async function pullParameters({ client, prefix, ...config }: Pull): Promise<Parameters> {
const paginator = paginateGetParametersByPath(
{
client: client ?? createClient(config),
},
{
Path: prefix,
Recursive: true,
WithDecryption: true,
}
)
const parameterList: Parameter[] = []
for await (const page of paginator) {
if (!page.Parameters) {
continue
}
for (const { Name, Value } of page.Parameters) {
if (Name) {
parameterList.push({ name: Name, value: Value ?? '' })
}
}
}
return _.sortBy(parameterList, (p) => p.name).reduce(
(parameters, { name, value }) => ({
...parameters,
[name.substr(prefix.length)]: value,
}),
{}
)
}