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

Answers 1

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


Related Articles