if (process.argv.length < 3) { throw `Usage: ${process.argv[1]} path_prefix` } const PATH_PREFIX = process.argv[2] const path = require('path') const AWS = require('aws-sdk') const ssm = new AWS.SSM() function getParametersByPath(nextToken, callback) { const params = { Path: PATH_PREFIX, Recursive: true, WithDecryption: true } if (nextToken) params['NextToken'] = nextToken ssm.getParametersByPath(params, (err, data) => { if (err) throw err callback(data) }) } function printParameter(parameter) { const envName = path.basename(parameter.Name) console.log(`${envName}="${parameter.Value}"`) } function handleResponse(response) { if (response.Parameters.length === 0) return response.Parameters.forEach(printParameter) if (!response.NextToken) return getParametersByPath(response.NextToken, handleResponse) } getParametersByPath(null, handleResponse)