Skip to content

Instantly share code, notes, and snippets.

@lampidudelj
Created September 20, 2019 10:23
Show Gist options
  • Save lampidudelj/2094c6089c0d2ef5ea6dafade38c8192 to your computer and use it in GitHub Desktop.
Save lampidudelj/2094c6089c0d2ef5ea6dafade38c8192 to your computer and use it in GitHub Desktop.
Get Parameters from SSM Store
import * as awsSdk from 'aws-sdk';
async function getParameterFromSystemManager( environment: string ) {
const ssm = new awsSdk.SSM();
const appId = environment.split('.')[0];
const stage = environment.split('.')[1].toUpperCase();
const params = {
Names: [`/${appId}/${stage}/cognito_user_pool_id`, `/${appId}/${stage}/queue_url`, `/${appId}/${stage}/table_name`]/* required */
};
try {
const ssmParamters = await ssm.getParameters(params).promise();
if(ssmParamters.Parameters.length > 0){
console.log(ssmParamters);
ssmParamters.Parameters.forEach(parameter => {
if(parameter.Name === `/${appId}/${stage}/cognito_user_pool_id`){
process.env.POOL_ID = parameter.Value;
} else if(parameter.Name === `/${appId}/${stage}/queue_url`) {
process.env.SQS_URL = parameter.Value;
} else if(parameter.Name === `/${appId}/${stage}/table_name`) {
process.env.DYNAMODB_TABLE = parameter.Value;
}
});
return Promise.resolve();
}
return Promise.reject({ name: 'GenericError', message: 'Function was not able to load the parameters.' });
} catch (err) {
console.log(err);
return Promise.reject({ name: 'GenericError', message: 'Function was not able to load the parameters.' });
}
}
export { getParameterFromSystemManager };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment