Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWSCognito Missing region in config error

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?

like image 511
abcf Avatar asked Feb 09 '23 07:02

abcf


1 Answers

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!

like image 110
Albert Vaca Cintora Avatar answered Feb 12 '23 12:02

Albert Vaca Cintora