Boto3 DynamoDB更新项目的列表属性 [英] Boto3 DynamoDB update list attributes for an item

查看:118
本文介绍了Boto3 DynamoDB更新项目的列表属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子,像这样:

  {"pKey":10001,项目": [{"name":"A",值":100},{"name":"B",值":100}]} 

我想将 items 列表中的所有 value 属性更新为200, items 列表中可以包含1到n个对象.

如何使用boto3 python dynamoDB低级客户端API做到这一点?

解决方案

我还没有真正测试过,但这就是我可以通过阅读

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?

解决方案

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')

这篇关于Boto3 DynamoDB更新项目的列表属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆