4

I'm trying to add elements in a table in dynamodb like in the example below but when I run it I get this error message: Missing credentials in the config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

aws.config.update({
   region: "eu-west-1",
   endpoint: "http://localhost:8080",})


  let ddb = new aws.DynamoDB.DocumentClient({
    apiVersion: "2012-08-10",
  });

  let params = {
    TableName: "NameOfTheTable",
    Item: {
      uuid: JSON.stringify(132), // random number for testing
      name: JSON.stringify(req.query.mod), //data i'm passing in
    },
  };

const addMod = ddb.put(params, function (err, data) {
  if (err) {
    console.log("Error", err);
  } else {
    console.log("Success", data);
  }
});
return res.send(addMod);

});

I think probably I'm missing the accessKeyId and the accessSecretKey but honestly, I did not understand how to set them

Gianmarco
  • 792
  • 2
  • 14
  • 38

1 Answers1

8

It seems you enquire credentials for local because the SDK checks for them, this has been raised as an issue it seems.

You can get around by specifying any string supposedly. Try the below snippet.

aws.config.update({
    region: "eu-west-1",
    endpoint: "http://localhost:8080",
    accessKeyId: “xxxxxx”,
    secretAccessKey: “xxxxxx”
});
Chris Williams
  • 32,215
  • 4
  • 30
  • 68
  • Hmm seems you have a circular reference somewhere in your codebase, https://stackoverflow.com/questions/4816099/chrome-sendrequest-error-typeerror-converting-circular-structure-to-json. Do you receive anything back by trying to access the dynamo dB host? – Chris Williams Jul 03 '20 at 21:07
  • https://stackoverflow.com/questions/52248078/error-putting-item-in-dynamodb-converting-circular-structure-to-json – Chris Williams Jul 03 '20 at 21:08
  • I already saw the second question but i did not solve, i don't where the circular reference come from, I also tried passing a string instead of the variable but nothig changed – Gianmarco Jul 03 '20 at 21:13
  • It seems that the error is unrelated to this question, I believe it’s the putitem. Might be worth raising as a separate question :) – Chris Williams Jul 03 '20 at 21:13
  • as you can see I tried put in addition to putItems – Gianmarco Jul 03 '20 at 21:15
  • If you comment out the put does it run? Just want to limit scope to that function :) – Chris Williams Jul 03 '20 at 21:17
  • the only error I get now with "put" is this one: Error Error [UnknownError]: Not Found message: 'Not Found', code: 'UnknownError', statusCode: 404, – Gianmarco Jul 04 '20 at 06:32
  • I also tried with putItems but I get some strange error – Gianmarco Jul 04 '20 at 06:32