in

Is it better to do a BatchWriteItem or several individual UpdateItem operations in DynamoDB?


I need to add one new attribute to multiple items at once in DynamoDB (possibly hundreds).

The easiest thing I can do is probably just:

 proposals = query_ddb_for_proposals(some_criteria)
 
 for proposal in proposals:
     proposal_table.update_item(
          Key={
               pk: proposal[pk],
               sk: proposal[sk]
          },
          AttributeUpdates={
               'approved': {
                   'Value': True
               }
          },
     )

This seems to work fine, but I was suggested to look into BatchWriteItem. I did look into this initially, but saw that BatchWriteItem doesn’t support update operations (only Put or Delete).

If I wanted to use BatchWriteItem with Puts for this, It looks like I’d need to get each “proposal”, add the new ‘approved’ value to it, and then include that as a Put operation so that it replaces the current item in DDB with the same item + the new value. To me, this seems less than ideal since we’re sending the full objects in each request and theoretically asking DDB to rewrite the whole item even though only one thing changed, but maybe DDB is smart enough to know to only change the one entry without considering the rest of the item?

Does anyone know of any docs on this difference or know about the difference from experience? In the meantime, I can try and see which one runs faster, I suppose.



Source: https://stackoverflow.com/questions/70717441/is-it-better-to-do-a-batchwriteitem-or-several-individual-updateitem-operations

Rotating a moving image with jquery

Studies carried out through Bootcamp Fullstack Cataline on Atomic Design and componentization in Vue