Unable to figure out how to increment DynamoDB counter using boto v2.25.0

The new interface does not seem to reveal ADD functionality for updates. I would like to do something like:

my_item = my_table.get_item(key=my_key,hash=my_hash)
my_item.add_attribute('count_votes',1)
my_item.partial_save()

It seems that in previous versions this would work. In 2.25 I get: AttributeError: the Item object does not have the attribute 'add_attribute'

+3
source share
1 answer

You are right, this add_attribute is not here right now. It looks like you need to use update_item api on boto.dynamodb.layer1.

Adding working code - I tried locally on DynamoDB:

conn.update_item(
    "table-1",
    {"firstKey":{"S":"12345"}},
    {"counter":{"Action":"ADD","Value":{"N":"1"}}}
)

Here it increments the counter by 1 on the table, which has "firstKey" as a Hashkey.

+3
source

All Articles