Last active
October 14, 2019 20:29
-
-
Save ChaseIngebritson/ba7b7f3e872e57476ab8a5ac023bd590 to your computer and use it in GitHub Desktop.
Loads parameters from the AWS parameter store . Binds the final hierarchy level in the provided name to a corresponding environment variable.
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') | |
require('dotenv').config() | |
AWS.config.update({ region: 'us-east-1' }); | |
const ssm = new AWS.SSM() | |
const params = [ | |
'/WebApp/ead/NodeJS/CampusMap/MONGODB_URI', | |
'/WebApp/ead/NodeJS/CampusMap/S3_BUCKET' | |
] | |
console.log('Loading parameter store...') | |
loadParameters(params).then(() => { | |
console.log('Parameter store loaded.') | |
}) | |
function loadParameters (params) { | |
const query = { | |
'Names': params, | |
'WithDecryption': true | |
} | |
return ssm.getParameters(query, (error, data) => { | |
if (error) throw new Error(error) | |
data.Parameters.forEach(param => { | |
const nameSections = param.Name.split('/') | |
const name = nameSections[nameSections.length - 1] | |
if (!process.env[name]) process.env[name] = param.Value | |
}) | |
}).promise() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment