AWS Secret Manager NodeJS JavaScript
const AWS = require("aws-sdk");
const region = your region;
const credentials = new AWS.SharedIniFileCredentials({
profile: "secret-manager",
});
AWS.config.credentials = credentials;
const client = new AWS.SecretsManager({
region: region,
});
const createSecrets = async (params) => {
const response = await new Promise((resolve, reject) => {
client.createSecret(params, (err, result) => {
if (err) reject(err);
if (result) {
resolve(result);
}
});
});
return response;
};
const getSecrets = async (SecretId) => {
const response = await new Promise((resolve, reject) => {
client.getSecretValue({ SecretId }, (err, result) => {
if (err) reject(err);
if (result) {
resolve(result.SecretString);
}
});
});
return JSON.parse(response);
};
module.exports = { getSecrets, createSecrets };
Aayush