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
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
id
getting defined – bryan60id
isn’t string. – Jason Wadsworth