0
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:2ce7b2c2-898f-4a26-9066-d4feff8ebfe4'
});
// Make the call to obtain credentials
AWS.config.credentials.get(function(){
// Credentials will be available when this function is called.
var accessKeyId = AWS.config.credentials.accessKeyId;
var secretAccessKey = AWS.config.credentials.secretAccessKey;
var sessionToken = AWS.config.credentials.sessionToken;
//var identityId = AWS.config.credentials.identityId;
return res.send({
accessKeyId: accessKeyId
});
});
所有變量都有空值。爲什麼?我究竟做錯了什麼?有沒有其他方法可以訪問它?從aws中獲取訪問令牌,祕密訪問密鑰和會話令牌
而且我應該送一個祕密密鑰和令牌來獲取會話密鑰
UPDATE:
當我嘗試這種方法,我得到一個錯誤說: 錯誤:NotAuthorizedException:未認證此身份池不支持訪問。
AWS.config.credentials.get(function(err) {
if (err) {
console.log("Error: "+err);
return;
}
console.log("Cognito Identity Id: " + AWS.config.credentials.identityId);
// Other service clients will automatically use the Cognito Credentials provider
// configured in the JavaScript SDK.
var cognitoSyncClient = new AWS.CognitoSync();
cognitoSyncClient.listDatasets({
IdentityId: AWS.config.credentials.identityId,
IdentityPoolId: ""
}, function(err, data) {
if (!err) {
console.log(JSON.stringify(data));
}
return res.send({
data: data
});
});
});
謝謝!我必須在aws控制檯設置中檢查允許未經身份驗證的連接。 – karankumar89