[英]boto3 Dynamodb table batch insert missing something
我希望這樣的事情能奏效。 我正在使用boto3接口將26個項目添加到dynamo數據庫中。
但是我丟失了一些東西,因為代碼報告了AttributeError: 'str' object has no attribute 'batch_write_item'
在第25個插入處AttributeError: 'str' object has no attribute 'batch_write_item'
(應該已經自動刷新了緩沖區)
from boto3.dynamodb import table
items = [
{'key': 1, u'timestamp': '1493269200000'},
{'key': 2, u'timestamp': '1493269200000'},
{'key': 3, u'timestamp': '1493269200000'},
{'key': 4, u'timestamp': '1493269200000'},
{'key': 5, u'timestamp': '1493269200000'},
{'key': 6, u'timestamp': '1493269200000'},
{'key': 7, u'timestamp': '1493269200000'},
{'key': 8, u'timestamp': '1493269200000'},
{'key': 9, u'timestamp': '1493269200000'},
{'key': 10, u'timestamp': '1493269200000'},
{'key': 11, u'timestamp': '1493269200000'},
{'key': 12, u'timestamp': '1493269200000'},
{'key': 13, u'timestamp': '1493269200000'},
{'key': 14, u'timestamp': '1493269200000'},
{'key': 15, u'timestamp': '1493269200000'},
{'key': 16, u'timestamp': '1493269200000'},
{'key': 17, u'timestamp': '1493269200000'},
{'key': 18, u'timestamp': '1493269200000'},
{'key': 19, u'timestamp': '1493269200000'},
{'key': 20, u'timestamp': '1493269200000'},
{'key': 21, u'timestamp': '1493269200000'},
{'key': 22, u'timestamp': '1493269200000'},
{'key': 23, u'timestamp': '1493269200000'},
{'key': 24, u'timestamp': '1493269200000'},
{'key': 25, u'timestamp': '1493269200000'},
{'key': 26, u'timestamp': '1493269200000'}
]
with table.BatchWriter('my_tbl_name',"us-east-1") as tbl:
for r in items:
tbl.put_item(r)
我也嘗試過使用tbl.put_item(str(r))
和其他一些東西(例如JSON編碼),但是沒有運氣。 有誰知道一個簡單的工作示例? 是的,我看過了,但是Boto和Boto3之間有很多混淆。
我所需要的只是一個Table
的實例。駱駝BatchWriter()
為上下文提供了錯誤的對象。 我需要batch_writer()
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('staging.tstable3')
print(table.creation_date_time)
with table.batch_writer() as batch:
for r in items:
batch.put_item(Item=r)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.