Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Require the module.
- var AWS_SM = require("awssecretmanager");
- // Request object. * Based on the requirement we can change it. *
- let feed = {
- region : "ap-south-1",
- secretName : "stage/db/mongoDB",
- env : "staging",
- appName : "auth"
- };
- // Util function to fetch the secret data based on the request object.
- AWS_SM.getSecretdata(feed, (err, secret)=>{
- if(err)
- throw err;
- else{
- // DB connection logic here.
- }
- });
- // Here I stored the KEY: VALUE pattern in secret manager is :
- "appName-env-keyName" : "value" Eg : "auth-staging-dbName" : "stagingDBName"
- Utils response for the above key value pair is
- "keyName" : "StagingDBName"
- If we want to store any secret data based on env & app, we have to follow the same pattern ("appName-env-keyName" : "value") in secret manager.
- Note : In case if we are following the other pattern, based on that we can optimise the Utility.
- Here to connect to the secretmanager I used my system aws configure data.
- Example Secret Data :
- //secretName : "stage/db/mongoDB"
- //region : "ap-south-1"
- "auth-staging-dbName" : "stagingDB",
- "auth-staging-userName" : "stagingDbAdmin",
- "auth-staging-password" : "admin@123",
- "auth-live-dbName" : "liveDB",
- "auth-live-userName" : "liveDbAdmin",
- "auth-live-password" : "admin@123"
- example request object for Util function :
- {
- region : "ap-south-1",
- secretName : "stage/db/mongoDB",
- env : "staging",
- appName : "auth"
- }
- Response from the util function is :
- {
- dbName : "stagingDB",
- userName : "stagingDbAdmin",
- password : "admin@123"
- }
- After receiving this data from the sesret manager, we can establish a DB connection (that is in application logic).
Add Comment
Please, Sign In to add comment