2017-08-27 68 views
0

當我嘗試使用Cognito登錄到已驗證的用戶時,出現以下錯誤。我正在嘗試訪問DynamoDB。Cognito:用戶登錄以驗證DynamoDB:錯誤:配置中缺少憑據:

Error: Missing credentials in config

"NotAuthorizedException: Missing credentials in config

AWS.config.update({region:'us-west-2'}); 
    if (cognitoUser != null) { cognitoUser.getSession(function(err, result) { 
    if (result) { 

     console.log('You are now logged in.'); 
     AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
       IdentityPoolId: config.IdentityPoolId, 
       Logins: { 
        "cognito-idp.us-west-2.amazonaws.com/us-west-2_XXXXXXX": result.getIdToken().getJwtToken() 
       } 
      }); 
     } 
    }); 
    } 



     var dynamoDB = new AWS.DynamoDB(AWS.config.credentials)    


     dynamoDB.listTables(function(err, data) { 
      if (err) console.log(err, err.stack); 
      else console.log(data.TableNames); 
     });    

回答

0

需要調用內部的cognitoUser.getSession(...)

發電機