![](/img/trans.png)
[英]AWS STS Assume Role - InvalidClientTokenId: The security token included in the request is invalid
[英]UnrecognizedClientException: The security token included in the request is invalid when calling AWS.SecretsManager
我正在实施 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 }
“请求中包含的安全令牌无效”错误几乎总是意味着您的凭据有问题。 accessKeyId 或 secretAccessKey(或两者)是错误的。
在您的代码中使用凭证之前,您可以尝试使用 AWS cli 使用STS get caller identity调用来验证您的凭证。
您需要为使用 aws configure 定义的 aws 提取您的令牌访问添加端点。 在创建表时添加此代码连接:
--endpoint-url http://localhost:8000 //localhost in my case because I'm runing locally, but you can put there you domain or port server
AWS.config.update({
region: "us-west-2",
endpoint: "http://localhost:8000",
accessKeyId: "your access id",
secretAccessKey: "your acccess key"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.