我正在尝试在 AWS-SDK v2 中为 Javascript 设置临时凭证:
const aws = require('aws-sdk')
aws.config = new aws.Config({
credentials: new aws.ChainableTemporaryCredentials({
params: {
RoleArn: roleArn, // Defined earlier
RoleSessionName: sessionName, // Defined earlier
DurationSeconds: 15 * 60
},
masterCredentials: new aws.Credentials({
accessKeyId: accessKeyId, // Defined earlier
secretAccessKey: awsSecretAccessKey // Defined earlier
})
}),
region: 'us-east-1',
signatureVersion: 'v4'
})
aws.config.getCredentials(function (err) {
if (err) console.log(err.stack)
else console.log('Access key:', aws.config.credentials.accessKeyId)
})
但是,我不断收到以下错误,该错误在调用 getCredentials 时发生:
CredentialsError: Could not load credentials from ChainableTemporaryCredentials
请注意,如果我将credentials
参数设置为主凭据而不是临时凭据,则它可以正常工作,如下所示:
aws.config = new aws.Config({
credentials: new aws.Credentials({
accessKeyId: accessKeyId, // Defined earlier
secretAccessKey: awsSecretAccessKey // Defined earlier
}),
region: 'us-east-1',
signatureVersion: 'v4'
})
有谁知道是什么导致了这个问题?这是我引用的文档: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html https ://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ChainableTemporaryCredentials.html