我有一个API网关,我已经使用aws4库从Node.js调用了以下格式:
let aws4 = require('aws4');
let request = {
host: 'myapi.execute-api.us-west-2.amazonaws.com',
method: 'GET',
url: 'https://myapi.execute-api.us-west-2.amazonaws.com/Prod/foos',
path: '/Prod/foos'
}
let signedRequest = aws4.sign(request,
{
secretAccessKey: AWS.config.credentials.secretAccessKey,
accessKeyId: AWS.config.credentials.accessKeyId
})
delete signedRequest.headers['Host']
delete signedRequest.headers['Content-Length']
let response = await axios(signedRequest)
现在,我们要停止直接在服务器上保存凭据,而是使用IAM角色。
当我尝试不使用凭据调用它时,无论是否使用aws4对其进行签名,都会出现此错误:
The security token included in the request is invalid.