When you use AWS.DynamoDB.DocumentClient()
it simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values. This abstraction annotates native JavaScript types supplied as input parameters, as well as converts annotated response data to native JavaScript types.
A Simple example is :
var params = {
Item: {
"Item1": "Value 1",
"Item2": "Value 1",
},
TableName: "Example"
};
var documentClient = new AWS.DynamoDB.DocumentClient();
documentClient.put(params, function (err, data) {
if (err) console.log(err);
else console.log(data);
});
However, when you use dynamodb client using new AWS.DynamoDB()
, you need to pass types and other notions. A simple example is:
var params = {
Item: {
"Item1": {
"S" : "Value 1",
},
"Item2": {
"N": 1000,
}
},
TableName: "Example"
};
var documentClient = new AWS.DynamoDB.DocumentClient();
documentClient.put(params, function (err, data) {
if (err) console.log(err);
else console.log(data);
});
As per the announcement of the DocumentClient:
The document client abstraction makes it easier to read and write data
to Amazon DynamoDB with the AWS SDK for JavaScript. Now you can use
native JavaScript objects without annotating them as AttributeValue
types.
Does DynamoDB require multiple JS files to be run simultaneously?
No, you don't need to.