我正在使用從我的 EC2 運行的 AWS-SDK 發出 Node.js API 請求。但他們不斷回傳錯誤 403:
{"message":"Missing Authentication Token"}
我正在嘗試訪問 Amazon SES 終端節點。我在 IAM 中設定了一個用戶,并添加了一個策略。它的策略名稱是AmazonSESFullAccess. 此用戶的密鑰和秘密存盤在~/.aws/credentials.
這應該足以驗證和授權我的請求:https ://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-shared.html
.env我還使用推薦AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY變數將它們添加到我的專案檔案中。
這也應該成功地驗證和授權我的呼叫:https ://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-environment.html
根據這些,如果我使用 AWS-SDK 發送我的請求,我不需要在標頭或查詢引數中對它們進行簽名:https ://docs.aws.amazon.com/general/latest/gr/簽署_aws_api_requests.html
這是代碼:
test: async () => {
/**
* Call AWS SES API
* Returns information about the account
* https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_GetAccount.html
*/
return new Promise(resolve => {
axios
.get("https://email.us-east-1.amazonaws.com/v2/email/account")
.then(res => {
console.log(res);
resolve(res);
})
.catch(error => {
console.error(error)
});
});
}
那么為什么我不能訪問任何資源呢?我能做些什么來修復它?
uj5u.com熱心網友回復:
您沒有使用 NodeJS AWS 開發工具包。您只是使用axios. 您發送的請求根本不知道任何 AWS 身份驗證憑證。
這就是您發出未經身份驗證的請求并收到相應錯誤“缺少身份驗證令牌”的原因。
您應該使用 AWS 開發工具包與 AWS API“對話”:
var sesv2 = new AWS.SESV2();
var params = {};
sesv2.getAccount(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
請參閱:https ://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SESV2.html#getAccount-property
AWS 開發工具包將讀取憑證并負責對請求進行身份驗證。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/443931.html
標籤:亚马逊网络服务 亚马逊 http-status-code-403 亚马逊 aws-sdk-nodejs
上一篇:從S3訪問Zip檔案
下一篇:如何修復FutterMqtt資料
