我正在实施 AWS ClientManager 以获取保存在 AWS 中的秘密变量。我的初始实现如下:
// Load the AWS SDK
var AWS = require('aws-sdk'),
region = "us-west-2",
secretName = "secretName",
accessKeyId = myAccessKey,
secretAccessKey = mySecretAccessKey,
secret,
decodedBinarySecret;
var client = new AWS.SecretsManager({
region: region,
});
client.getSecretValue({SecretId: secretName}, function(err, data) {
if (err) {
console.log("Error Happened");
console.log(err);
}
else {
if ('SecretString' in data) {
secret = data.SecretString;
} else {
let buff = new Buffer(data.SecretBinary, 'base64');
decodedBinarySecret = buff.toString('ascii');
}
}
});
当我启动服务器时,它会引发以下异常
{ UnrecognizedClientException:请求中包含的安全令牌无效。消息:'请求中包含的安全令牌无效。',代码:'UnrecognizedClientException',时间:2019-07-01T12:16:00.021Z,requestId:'c7ed53c1-fb70-4012-aa9f-5a9a3195a043',状态代码: 400,可重试:假,重试延迟:40.923844792180674 }