0

I am upgrading nodejs from older version to node 16 as AWS-SDK has announced end of support for Node.js 14.x. i am using dynamoose package for dynamodb connection and other operations. now with nodejs 16, getting region is missing error even though region is set at all possible ways

Error: Region is missing at default (/home/myproject/node_modules/@aws-sdk/config-resolver/dist-cjs/regionConfig/config.js:10:15)

tried all these methods to set region

1. const ddb = new dynamoose.aws.ddb.DynamoDB({
        region: config.aws.region,
        accessKeyId: config.aws.accessKeyId,
        secretAccessKey: config.aws.secretAccessKey,
    });
    // Set DynamoDB instance to the Dynamoose DDB instance
    dynamoose.aws.ddb.set(ddb);

2.  var AWS = require('aws-sdk');
    AWS.config.loadFromPath('./aws.json');
    AWS.config.getCredentials(function(err) {
        if (err) console.log(err.stack);
        // credentials not loaded
        else {
          console.log("Access key:", AWS.config.credentials.accessKeyId);
          console.log("secretAccessKey:", AWS.config.credentials.secretAccessKey);
          console.log("credentials.region:", AWS.config.credentials.region);
          console.log("region: ", AWS.config.region);
        }
      });
    Able to get AWS.config.region in logs :
    Access key: XXXXX
    secretAccessKey: XXXXXXXXXXXXXXXXXX
    credentials.region: undefined
    region: ap-southeast-1
    aws version: 2.1231.0

 3. AWS.config.update({region:'ap-southeast-1'});

4. set region if not set (as not set by the SDK by default)
    if (!AWS.config.region) {
      AWS.config.update({
        region: 'eu-west-1'
      });
    }

please help me to resolve this issue

  • node -v : v16.17.1
  • npm -v : 8.15.0
  • aws version: 2.1231.0
  • dynamoose : 3.1.0
  • Just to confirm, everything works fine with Node 14? Have you tried deleting `node_modules`, `package-lock.json`, clearing NPM cache before installing dependencies with Node 16? – Bill_BsB Oct 13 '22 at 14:17

1 Answers1

0

A bit late to the party but I had a run in with this and it's a bit confusing. Apparently, dynamoose uses AWS system configs for local (even though it can be a random set of strings). So what I had to do was

  1. install aws-cli
  2. use aws configure in terminal/powershell
  3. provide your accessID, secret-key, region (mainly this)

Then it should work fine

Nishanta Khanal
  • 316
  • 2
  • 4