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