I am learning DynamoDB and AWS serverless stack. I see that a lot of tutorials suggest using AWS.DynamoDB.DocumentClient. For example, to create an item:
const dynamodb = new AWS.DynamoDB.DocumentClient();
and then
try {
await dynamodb
.put({
TableName: process.env.DISHES_TABLE_NAME,
Item: dish,
})
.promise();
} catch (error) {
console.error(error);
throw new createError.InternalServerError(error);
}
But the doc says that put
Creates a new item, or replaces an old item with a new item by delegating to AWS.DynamoDB.putItem()
I am confused why not use AWS.DynamoDB.putItem in the first place or when to use which one.
Thank you!
From the documentation the DocumentClient is just an abstract class to make it easier to implement.
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.
You're free to choose whichever method you want, however by using the DocumentClient class you would be having less control over the processing or manipulation of your data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With