DynamoDB Batch Update

Amazon Dynamodb

Amazon Dynamodb Problem Overview


Is there any API in DynamoDB to update a batch of items? There is an API to write new items in batches (BatchWriteItem) and update single item using UpdateItem, but is it possible to update multiple items in one call?

Amazon Dynamodb Solutions


Solution 1 - Amazon Dynamodb

There is no batch update item API available in DynamoDB at the moment.

DynamoDB API operations list

Solution 2 - Amazon Dynamodb

I know this is an old question by now, but DynamoDB recently added a Transaction api which supports update:

Update — Initiates an UpdateItem operation to edit an existing item's attributes or add a new item to the table if it does not already exist. Use this action to add, delete, or update attributes on an existing item conditionally or without a condition.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html

Solution 3 - Amazon Dynamodb

Solution 4 - Amazon Dynamodb

I reached this thread on similar query, hope this might help.

DynamoDB supports Batch Statement Execution which is described in documentation. This works with client object rather than resource object. Then I used the PartiQL update statement supported by DynamoDB and described here.

Python code reference looks something like this:

client = boto3.client('dynamodb')

batch = ["UPDATE users SET active='N' WHERE email='<user_email>' RETURNING [ALL|MODIFIED] [NEW|OLD] *;", "UPDATE users ..."]  # Limit to 25 per batch
request_items = [{'Statement': _stat} for _stat in batch]
batch_response = client.batch_execute_statement(Statements=request_items)

This is minimal code. You can use multi-threading to execute multiple batches at once.

Solution 5 - Amazon Dynamodb

BatchWriteItem cannot update items. To update items, use the UpdateItem action. BatchWriteItem operation puts or deletes multiple items in one or more tables

Reference: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html

Solution 6 - Amazon Dynamodb

I use DynamoDBMapper.batchSave(Iterable<? extends Object> objectsToSave) for this purpose.

Solution 7 - Amazon Dynamodb

No there is no batch update currently , you can use a single update Item call and have a workflow over it like AWS SWF or AWS step functions

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html

Solution 8 - Amazon Dynamodb

I use a dynamoDB update trigger, then I made a template that said to me what items I should modify, I put them on a queue and them read queue messages in other to update one by one

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1846749View Question on Stackoverflow
Solution 1 - Amazon DynamodbnotionquestView Answer on Stackoverflow
Solution 2 - Amazon DynamodbChris BarrettView Answer on Stackoverflow
Solution 3 - Amazon DynamodbSajedView Answer on Stackoverflow
Solution 4 - Amazon Dynamodbap14View Answer on Stackoverflow
Solution 5 - Amazon Dynamodbuser3417670View Answer on Stackoverflow
Solution 6 - Amazon DynamodbMarianView Answer on Stackoverflow
Solution 7 - Amazon Dynamodbswarnim guptaView Answer on Stackoverflow
Solution 8 - Amazon DynamodbClara JustinoView Answer on Stackoverflow