aws.config.update() not updating the AWS credentials

9.8k views Asked by At

I'm fairly new to using AWS and aws-cli. I'm trying to update a dynamo DB table by writing a node script using aws-SDK.I have created a shared credential file that has all the credentials from two of my aws accounts and now I'm having trouble configuring the relevant credentials to the script that I'm trying to run to update the Db. Therefore I used aws.config.update() method to update the configurations but it still doesn't do the job , hence I get the "ResourceNotFoundException" when I run the code. Here's my code.

const aws = require("aws-sdk");

aws.config.update({
  accessKeyId: "xxxxxxxx",
  accessSecretKey: "xxxx",
  region: "ap-south-1",
});
const docClient = new aws.DynamoDB.DocumentClient();
async function update() {
  try {

    var params = {
   
      TableName: "employee",
      Key: {
      
        ID: "1",
      },
      UpdateExpression: "set EmployeeName =:fullName",
      ExpressionAttributeValues: {
        ":fullName": "test 3",
      },
    };
    var result = docClient.update(params, function (err, data) {
      if (err) console.log(err);
      else console.log(data);
    });
    console.log(result);
  } catch (error) {
    
    console.error(error);
  }
}
update();

Please help me find a solution set up the relevant configurations and the reason behind aws.config.update() not working for me .

1

There are 1 answers

4
CyberEternal On BEST ANSWER

You can try this way

import AWS from "aws-sdk"

const docClient = new AWS.DynamoDB.DocumentClient({ region: config.region, accessKeyId: config.accessKeyId, secretAccessKey: config.secretAccessKey });

If I'm not mistaken, You will get the "ResourceNotFoundException" error, when your DynamoDB table did not exist. Check your AWS credentials, please.