我需要使用从秘密管理器中检索到的秘密来配置 knexfile.js。我从秘密管理器中检索秘密并将其存储在秘密变量中并在配置中使用它。
var AWS = require('aws-sdk'),
endpoint = "abcd",
region = "us-east-1",
secretName = "abcd",
secret,
binarySecretData;
var client = new AWS.SecretsManager({
endpoint: endpoint,
region: region
});
client.getSecretValue({
SecretId: secretName
}, function (err, data) {
if (err) {
if (err.code === 'ResourceNotFoundException')
console.log("The requested secret " + secretName + " was not found");
else if (err.code === 'InvalidRequestException')
console.log("The request was invalid due to: " + err.message);
else if (err.code === 'InvalidParameterException')
console.log("The request had invalid params: " + err.message);
} else {
if (data.SecretString !== "") {
secret = data.SecretString;
} else {
binarySecretData = data.SecretBinary;
}
}
});
module.exports = {
development: {
client: secret.localClient,
connection: {
host: secret.localHost,
user: secret.localUser,
password: secret.localPassword,
database: secret.localDatabase,
charset: "utf8"
}
},
};
但它显示错误 TypeError: Cannot read property 'localClient' of undefined