Ali
Ali

Reputation: 19682

In dynamodb can you use "put" instead of "update_item"

I want to update an item in dynamodb using boto, and the way I do it, I need to get_item it first anyways, then I change the item and put it back, is there any difference, performance penalty or otherwise, to do it using update_item and not put.

Upvotes: 1

Views: 3484

Answers (2)

greg
greg

Reputation: 6913

Save the throughput and only update the fields that need to be updated. The only downside to update_item is that it's not available as a batch function.

Correction: As noted in the comments, Dynamo actually uses the largest record to calculate the write capacity so if you only update one field, it will still calculate the write based on the total size of the record that already exists, this also applies if you PUT a record with the same ID.

Upvotes: 5

yadutaf
yadutaf

Reputation: 7132

I am not aware of any performance differences between the two. Anyway, with DynamoDB, you pay for guaranteed throughput.

This said, UpdateItem allows you to edit only a specific subset of an item. Moreover, this is the only way to use atomic increments.

If you have a very big Item and want to update a single small field then you should use UpdateItem instead so spare WriteCapacity. But this is the main usecase.

Upvotes: 6

Related Questions