0

I have a table like:

{
"pKey": 10001,
"items": [
    {
        "name": "A",
        "value": 100
    },
    {
        "name": "B",
        "value": 100
    }
]
}

I would like to update all value attributes in items list to be 200, items list can have 1 to n objects.

How can I do that using boto3 python dynamoDB low-level client APIs?

MatrixZ
  • 46
  • 5

1 Answers1

3

I haven't really tested this but this is what I can come up just by reading the docs:

import boto3

ddb = boto3.resource('dynamodb')
table = ddb.Table('your_table')

document = table.get_item(Key={'pKey': 10001})['Item']

for item in document['items']:
    item['value'] = 200

table.put_item(Item=document, ReturnValues='NONE')
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
  • 1
    Appreciate this simple solution. However, I wonder if the `get_item` + `put_item` cost the same as `update_item` API, since I have potentially billions of entries need to be updated. This seems like rewrite all of them, it can cost a lot. – MatrixZ Apr 13 '18 at 23:01
  • Works great for me. – Matt Parrilla Oct 04 '18 at 11:41