Reputation: 725
I have a table in DynamoDB with following attributes and respective values in a row.
Now I want to add attribute5, attribute6, attribute7 to the same row in my table without changing the existing attribute values.
I tried the below code and its deleting old attribute value.
try:
my_table.put_item(Item={'key': keyvalue,'attribute5': 0, 'attribute6':0, 'attribute7':0})
except Exception as e:
logger.error("at method add_source_defaults %s", e)
How can i achieve this task.
Upvotes: 1
Views: 2756
Reputation: 429
You need to update your item by getting it with your table hash key and then update it like this.
from boto.dynamodb2.table import Table
my_table = Table('tablename')
item = my_table.get_item(key ='keyvalue')
item['attribute5'] = 0
item['attribute6'] = 1
item['attribute7'] = 2
item.save()
Upvotes: 3