Difference between AWS SDK DynamoDB client and DocumentClient?

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.

It's basically a simpler way of calling dynamoDB in the SDK and it also converts annotated response data to native JS types. Generally you should only use the regular DynamoDB client when doing more "special" operations on your database like creating tables etc. That's stuff usually outside of the CRUD-scope.


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()).


In simpler words, DocumentClient is nothing, but wrapper around DynamoDB client. As per mentioned in other comments and aws documentation below, it features convenience of use, converting annotated response data to native JS types and abstracting away the notion of attribute values.

Another noticeable difference is that the scope of documentclient is limited to item level operations, but dynamodb client provides broader range of operations in addition to the item level operations.

From AWS document client documentation

The document client 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.