AWSCognito Missing region in config error

邮差的信 提交于 2019-12-23 17:24:42

问题


I'm using the aws-sdk javascript in my back-end and I can use AWS fine but when I try to use the getOpenIdTokenForDeveloperIdentity method I get a "Missing region in config error" as a response.

var config = new AWS.Config({
  accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETYKEY", region: 'us-east-1'
});

var params = {
  IdentityPoolId: 'MYIDENTITYPOOLID', /*   required */
  Logins: { /* required */
    "login.my.myapp": 'string',
    /* anotherKey: ... */
  },
  IdentityId: null,
  TokenDuration: 0
};

cognitoidentity.getOpenIdTokenForDeveloperIdentity(params,function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else console.log(data);               // successful response
});

In the docs it said that:

By default, credentials and region settings are left unconfigured. This should be configured by the application before using any AWS service APIs.

So I set my region but why am I still getting an error?


回答1:


You are setting the region in a local config variable. It should be set in the global AWS.config, like this:

AWS.config.region = 'us-east-1';

The same applies for the credentials. In case you want to use Amazon Cognito Credentials for all your AWS clients, you should initialize AWS.config.credentials like this:

AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'YOUR_POOL_ID'
});

I hope this helps!



来源:https://stackoverflow.com/questions/31976202/awscognito-missing-region-in-config-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!