2

I am working on a nodejs based api using aws dynamodb. API was working fine but today i am getting this error:

{
    "success": false,
    "message": {
        "message": "Missing region in config",
        "code": "ConfigError",
        "time": "2020-08-17T19:17:17.462Z"
    }
}

Below is my user api route:

const AWS = require('aws-sdk');
const config = require('config');
const { v4: uuidv4 } = require('uuid');
// Set the region
AWS.config.update({ region: 'us-east-2' });

router.post(`/api/user`, (req, res) => {
    console.log('User Add Services Called');

    try {
        //Constants
        AWS.config.update(config.aws_remote_config);

        var params = {
            TableName: config.aws_table_name,
            Item: {
                PK: `${uuidv4()}`,
                SK: `User`,
                name: 'Test'
            }
        };

        //Calling DynamoDB to add the item to the table
        docClient.put(params, function (err) {
            if (err) {
                res.send({
                    success: false,
                    message: err
                });
            } else {
                res.send({
                    success: true,
                    message: 'User Added'
                });
            }
        });
    } catch (error) {
        return res.status(500).json({
            status: 'error',
            message: 'An error occurred trying to process your request'
        });
    }
});

Some time these error shows too:

  • connect ENETUNREACH 169.254.169.254:80
  • Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

Can anyone tell why its happening, API was working fine & I also tried regenerating access keys too but the same issue is coming

2
  • any solution yet guys? Commented Aug 18, 2020 at 5:01
  • 1
    having the same issue after using api for couple of days. Commented Aug 18, 2020 at 5:04

1 Answer 1

1

I think you are re-configuring the AWS.config which is overwriting your initial config update that contains the region initialization. Try this:

const AWS = require('aws-sdk');
const config = require('config');
const { v4: uuidv4 } = require('uuid');

// Set the region
AWS.config.update({ region: 'us-east-2', ...config.aws_remote_config });

router.post(`/api/user`, (req, res) => {
    console.log('User Add Services Called');

    try {
        var params = {
            TableName: config.aws_table_name,
            Item: {
                PK: `${uuidv4()}`,
                SK: `User`,
                name: 'Test'
            }
        };

        //Calling DynamoDB to add the item to the table
        docClient.put(params, function (err) {
            if (err) {
                res.send({
                    success: false,
                    message: err
                });
            } else {
                res.send({
                    success: true,
                    message: 'User Added'
                });
            }
        });
    } catch (error) {
        return res.status(500).json({
            status: 'error',
            message: 'An error occurred trying to process your request'
        });
    }
});

EDIT

Then that means your credentials are missing simply do this:


// ... Other code

// Set the region
AWS.config.update({ 
    ...config.aws_remote_config,
    region: 'us-east-2',
    credentials: {
        accessKeyId: 'your-access-key',
        secretAccessKey: 'your-secret-key'
    } });

// ... Other code

Sign up to request clarification or add additional context in comments.

2 Comments

if I do that then this response comes: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
I am already passing all these in the array. If the sequence was the issue then it should not be working from start. My question remains the same, why it stopped working? it was working fine before

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.