1
votes

I am new to DynamoDB docClient for Node. I am trying to do a simple read an item call but it throws this error

The provided key element does not match the schema

The link that I am following https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html#GettingStarted.NodeJs.03.02

Here is my code

const id = req.params; //value is 83166ce1-b36b-4074-b586-e2468346eb03
const docClient = new AWS.DynamoDB.DocumentClient();

const params = {
  TableName: 'users',
  Key: {
    'id': id,
  }
};

docClient.get(params, function(err, data) {
  if (err) {
    console.log(err);
    res.status(500).send("Error fetching user item from DB");
  } else {
    res.status(200).json(data.promoCredits);
  }
});

Here is my table configuration Table Configuration

My Items

Items in Table

I have tried to google but I cannot find an answer to this. Currently I am returning all my users and manually filtering but that is not the optimal solution. Please help.

Hitting my request like this

http://localhost:8081/api/user/getPromoCredits/83166ce1-b36b-4074-b586-e2468346eb03

my endpoint config is

app.get('/api/user/getPromoCredits/:id', user.getUserPromoCredits);

Thank you

1
where / how is id getting definedbryan60
My assumption is that the type of id isn’t string.Jason Wadsworth
You guys are correct, thank you so much!Nuruddin Nasiruddin

1 Answers

0
votes

It was an issue where I was not deconstructing my id, and id was of type Object. Based on the two comments above, thank you so much for your help...

Updated to

const { id } = req.params;