Reputation: 994
I need to update one item of DynamoDB, here is my Code.
const Aws = require('aws-sdk');
const endPoint= 'http://dynamodb.us-east-2.amazonaws.com';
const IAm_user_Key=process.env.IAM_USER_KEY;
const IAm_user_Secret=process.env.IAM_USER_SECRET;
Aws.config.update({ accessKeyId:IAm_user_Key,secretAccessKey:IAm_user_Secret,region:'us-east-2',endpoint:endPoint });
var docClient = new Aws.DynamoDB.DocumentClient();
var table = "cards";
var params={
TableName:table,
key:{ "cardid":clientData.data.cardid},
AttributeValue:{"data":clientData.data}
}
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Added item:", JSON.stringify(data, null, 2));
}
})
I am facing issues while running this code here my error.
Unable to update item. Error JSON: {
"message": "Missing required key 'Key' in params",
"code": "MissingRequiredParameter",
"time": "2019-07-20T07:47:06.490Z"
}
But you can see I have Key object in params but still struggling for this.
Upvotes: 2
Views: 3395
Reputation: 1
var params={
TableName:table,
Key:{ "cardid":clientData.data.cardid, 'name': req.body.name},
AttributeValue:{"data":clientData.data}
}
Upvotes: 0
Reputation: 994
I read docs too many times but there is a silly mistake, I found it is just typo error "key" in params should be "Key" K in uppercase only and this is working.
Upvotes: 4