Difference between DynamoDb PutItem vs UpdateItem?

前端 未结 3 1848
情话喂你
情话喂你 2020-12-25 10:21

Based on DynamoDb documentation why would anyone use updateItem instead of putItem?


  • PutItem - Writes a single ite
3条回答
  •  半阙折子戏
    2020-12-25 11:21

    PutItem overwrites the whole item (all attributes) with the new version being passed while UpdateItem will only Update the passed attributes

    Performance: PutItem may affect on the performance if you overwrite the entire item so often as it involves more operations than UpdateItem FindItem, DeleteOldVersion, and AddNewVersion

    From cost prospective, it is different as well:

    AWS calculates the cost based on used read/write capacity units that are completely tied to the size of the item being overwritten/updated.

    In case of PutItem, the size will be the larger of the new and old versions of the item. For example, replacing a 2 KB item with a 1 KB, It will consume 2 WCUs however subsequent requests will only use 1 WCU. so if you're overwriting so often and the size of the item changes heavily that will calculate always the larger version of the item and affects on the cost.

    In case of modifying items using UpdateItem, the size includes all of the item’s pre-existing attributes, not the larger version like PutItem :) but also not just the ones being added or updated :(

提交回复
热议问题