'DynamoDBVersionAttribute for a frequency field

I have a DDB table, 4 attributes, key (PK - a string), date (sort/range key), status, frequency. I have multiple clients that will write to this table based on the 'key' and date value

I want to increment frequency every time a client makes a write.

Can I just use DynamoDBVersionAttribute on an int field and use this as a proxy for frequency?

I understand this is not meant for this use case, but I want to avoid having to first read and then write the item. Any thoughts?



Solution 1:[1]

Since you're already doing an update expression, just add an ADD action to increment the frequency by 1. The ADD action doesn't need to know the original value to increment it.

See the example from the docs here: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.SET.IncrementAndDecrement

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hunterhacker