Reputation: 994
I am trying to get single Item through dynamoDB using Javascript here my code
var params = {
TableName: 'sharedata',
Key: {
id: _id
},
ProjectionExpression: 'ATTRIBUTE_NAME'
};
ddb.getItem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.Item);
}
});
and here my table in dynamoDB.
I am facing error: Expected params.Key['id'] to be a structure. What I am missing I am trying same as per docs reading writing a single Item in dynamoDB
Upvotes: 0
Views: 368
Reputation: 1079
The Object to be formatted in a AttributeValue representation. That means you would have to change this
var params = {
TableName: 'sharedata',
Key: {
id: {S:_id}
},
ProjectionExpression: 'ATTRIBUTE_NAME'
};
Upvotes: 1
Reputation: 3606
The error
error: Expected params.Key['id'] to be a structure
is indicating that key is not formed correctly in the request. From the docs:
var params = {
TableName: 'TABLE',
Key: {
'KEY_NAME': {N: '001'}
},
ProjectionExpression: 'ATTRIBUTE_NAME'
};
Try this out:
var params = {
TableName: 'sharedata',
Key: {
id: {S: _id}
},
ProjectionExpression: 'ATTRIBUTE_NAME'
};
Upvotes: 3