5

I'm trying to update an item where I need to edit about different 150 attributes on the item and I'm getting Invalid UpdateExpression: Expression size has exceeded the maximum allowed size. I assume it's because my UpdateExpression string is very long. AWS docs say that the maximum length of an expression parameters is 4kb.

How would I go about reconciling this error? I guess I could break the request down into multiple but that seems dirty.

There are some other questions on here about the Item size limit but I haven't found anything about the UpdateExpression limit.

Solution:

I ended up limiting the request to 50 attribute updates and that along with transactWrite and ConsistentRead fixed my issue.

Lucas D
  • 460
  • 1
  • 4
  • 15

2 Answers2

1

I didn't run to a very long update query for DynamoDB, but for me anything more than 50 updates, I would split it to 2 update requests!

Aram Zuhairi
  • 175
  • 2
  • 5
1

You have indeed reached the limit for expression parameters.

Technically you can get around this if you construct another PutItem request which will replace the item that was there previously.

By doing any writes (including updates) you will need to wait for result to be propagated to the nodes your DynamoDB table uses (because of eventual consistency), or use strong consistent reads when you try to perform a GetItem, Query or Scan request that must return this item immediately after the write.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
  • Do you mean updating the item locally then using `PutItem` instead of `updateItem`? – Lucas D Jul 11 '20 at 19:36
  • 1
    Yes, you would build the entire item again then put. It might not work for what you want but it does replace the previous item essentially updating all attributes at once – Chris Williams Jul 11 '20 at 19:40
  • I see. I think I'd rather just break the update down into multiple requests in order to avoid overwrites. However, I then run into another problem described in this post https://stackoverflow.com/questions/62853684/dynamodb-missing-updates-with-concurrent-requests – Lucas D Jul 11 '20 at 19:59