Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save takahirohonda/19a664dc9738c48858af384b92ba8471 to your computer and use it in GitHub Desktop.

Select an option

Save takahirohonda/19a664dc9738c48858af384b92ba8471 to your computer and use it in GitHub Desktop.
node-module-to-retrieve-multiple-parameters-from-aws-parameter-store-1.js
'use strict';
const AWS = require('aws-sdk');
let ssm;
const getParameters = async (parameterNames, region, apiVersion='2014-11-06') => {
if (!ssm) {
ssm = new AWS.SSM({apiVersion: apiVersion, region: region});
}
const params = {
Names: parameterNames,
WithDecryption: true
};
try {
const parameters = await ssm.getParameters(params).promise();
return formatParameters(parameters);
} catch (e) {
return e;
}
};
const formatParameters = (parameters) => {
return parameters.Parameters.reduce((object, param) => {
return { ...object, [param.Name]: param.Value };
}, {});
};
module.exports = { getParameters };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment