Created
August 28, 2019 04:44
-
-
Save TimothyJones/8d71a52665bca3196a6c19488efbc2c4 to your computer and use it in GitHub Desktop.
Example showing a promisified SSM config reader for SecureString parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AWS = require('aws-sdk'); | |
const ssm = new AWS.SSM(); | |
const configFeatures = { | |
'/path/to/your/config/option': 'someOption', | |
'/path/to/your/config/something_else': 'somethingElse' | |
}; | |
const getConfig = () => | |
new Promise((resolve, reject) => { | |
ssm.getParameters( | |
{ | |
Names: Object.keys(configFeatures), | |
WithDecryption: true | |
}, | |
(err, data) => { | |
if (err) { | |
console.log(err, err.stack); | |
reject(err); | |
} else { | |
const config = data.Parameters.reduce( | |
(cfg, i) => ({ | |
...cfg, | |
[configFeatures[i.Name]]: i.Value | |
}), | |
{} | |
); | |
resolve(config); | |
} | |
} | |
); | |
}); | |
module.exports = getConfig; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment