Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between AWS SDK DynamoDB client and DocumentClient?

I want to know the difference between the AWS SDK DynamoDB client and the DynamoDB DocumentClient? In which use case should we use the DynamoDB client over the DocumentClient?

const dynamoClient = new AWS.DynamoDB.DocumentClient();  vs   const dynamo = new AWS.DynamoDB();  
like image 489
Thiwanka Wickramage Avatar asked Sep 05 '19 11:09

Thiwanka Wickramage


People also ask

What is AWS SDK for DynamoDB?

Description. AWS SDK for JavaScript DynamoDB Client for Node. js, Browser and React Native. Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability.

How do I access DynamoDB from AWS SDK?

Be sure to configure the SDK as previously shown. To access DynamoDB, create an AWS. DynamoDB service object. Create a JSON object containing the parameters needed to add an item, which in this example includes the name of the table and a map that defines the attributes to set and the values for each attribute.

Which is the method of DynamoDB document client is used for returning one or more items and item attributes by accessing every item in a table?

putItem() . Directly access items from a table by primary key or a secondary index. Returns one or more items and item attributes by accessing every item in a table or a secondary index.

What is difference between scan and query in DynamoDB?

DynamoDB supports two different types of read operations, which are query and scan. A query is a lookup based on either the primary key or an index key. A scan is, as the name indicates, a read call that scans the entire table in order to find a particular result.


1 Answers

I think this can be best answered by comparing two code samples which do the same thing.

Here's how you put an item using the dynamoDB client:

var params = {     Item: {         "AlbumTitle": {             S: "Somewhat Famous"         },         "Artist": {             S: "No One You Know"         },         "SongTitle": {             S: "Call Me Today"         }     },     TableName: "Music" }; dynamodb.putItem(params, function (err, data) {     if (err) console.log(err)     else console.log(data);            }); 

Here's how you put the same item using the DocumentClient API:

var params = {     Item: {         "AlbumTitle": "Somewhat Famous",         "Artist": "No One You Know",         "SongTitle": "Call Me Today"     },     TableName: "Music" };  var documentClient = new AWS.DynamoDB.DocumentClient();  documentClient.put(params, function (err, data) {     if (err) console.log(err);     else console.log(data); }); 

As you can see in the DocumentClient the Item is specified in a more natural way. Similar differences exist in all other operations that update DDB (update(), delete()) and in the items returned from read operations (get(), query(), scan()).

like image 197
Itay Maman Avatar answered Oct 13 '22 04:10

Itay Maman