vbo*_*r00 1 python amazon-web-services amazon-dynamodb
我有以下字典列表:
datalist = [
{'Business': 'Business A', 'Category': 'IT', 'Title': 'IT Manager'},
{'Business': 'Business A', 'Category': 'Sourcing', 'Title': 'Sourcing Manager'}
]
Run Code Online (Sandbox Code Playgroud)
我想以以下格式上传到 DynamoDB:
table.put_item(Item={
'Business':'Business A would go here',
'Category':'IT would go here',
'Title':'IT Manager would go here'
},
{
'Business':'Business B would go here',
'Category':'Sourcing would go here',
'Title':'Sourcing Manager would go here'
}
)
Run Code Online (Sandbox Code Playgroud)
我尝试先将字典列表转换为字典,然后以这种方式访问元素,或者尝试迭代 Items 参数,但没有成功。任何帮助,将不胜感激。
这是我的 DynamoDB 结构,有 3 列(业务、类别、标题):
{
"Business": {
"S": "Business goes here"
},
"Category": {
"S": "Category goes here"
},
"Title": {
"S": "Title goes here"
}
}
Run Code Online (Sandbox Code Playgroud)
APIput_item调用允许您只上传一项,但您尝试同时上传两项,这是行不通的。
您可以使用 boto3 批量处理多个放置项目请求,以减少 API 调用次数。这是改编自文档的示例:
with table.batch_writer() as batch:
for item in datalist:
batch.put_item(
Item=item
)
Run Code Online (Sandbox Code Playgroud)
这将在后台自动创建批量写入。
| 归档时间: |
|
| 查看次数: |
7403 次 |
| 最近记录: |