Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDb Batch write update

When we do table.batch_writer() , the boto3 API , does it insert or it updates as well?

By Update i mean the partition key, sort key are same , but other attributes are not same.I cannot find this in any documentation.

like image 725
vks Avatar asked Jun 28 '17 14:06

vks


1 Answers

The batch_writer in Boto3 maps to the Batch Writing functionality offered by DynamoDB, as a service. This Batch Writing refers specifically to PutItem and DeleteItem operations and it does not include UpdateItem.

From the docs:

The BatchWriteItem operation puts or deletes multiple items in one or more tables. A single call to BatchWriteItem can write up to 16 MB of data, which can comprise as many as 25 put or delete requests. Individual items to be written can be as large as 400 KB.

Note

BatchWriteItem cannot update items. To update items, use the UpdateItem action.

To be clear, the PutItem operation either inserts a new item or replaces an item, uniquely identified by its key (either partition-only, or composite partition+sort key based on how the table was defined). So in a way, you may think of replacing an item as updating it's non-key attributes but it's more correct to think of that as a replace rather than an update. Contrast this with the UpdateItem API which allows selective manipulation of an item's attributes.

It's worth mentioning that even with Put & Delete item functions, the batch API is more limiting than doing individual PutItem or DeleteItem calls because it doesn't support conditional writes. The BatchWrite API is really only useful for batch loading, or batch deleting of data to save on network overhead with respect to HTTP headers, additional compute resources to generate & verify SigV4 signature, etc.

like image 99
Mike Dinescu Avatar answered Sep 19 '22 03:09

Mike Dinescu