dla*_*ser 2 python boto amazon-dynamodb
我试图使用boto库将项添加到dynamodb表.这似乎很简单.我的代码是:
import boto.dynamodb
c = boto.dynamodb.connect_to_region(aws_access_key_id="xxx",
                                    aws_secret_access_key="xxx",
                                    region_name="us-west-2")
users = c.get_table("users")
users.put_item(data={'username': 'johndoe', 
                     'first_name': 'John',
                     'last_name': 'Doe'})
但是,我收到以下错误:
'Table' object has no attribute 'put_item'
我认为我连接到数据库很好,并得到了users表(users变量是类型:) boto.dynamodb.table.Table.所以,我不确定为什么它找不到put_item方法(我甚至检查Table了boto库中类的代码,它有put_item方法).任何见解都将受到高度赞赏.
您正在使用DynamoDB v1界面.为此使用以下语法:
item_data = {
    'Body': 'http://url_to_lolcat.gif',
    'SentBy': 'User A',
    'ReceivedTime': '12/9/2011 11:36:03 PM',
}
item = table.new_item(
    # Our hash key is 'forum'
    hash_key='LOLCat Forum',
    # Our range key is 'subject'
    range_key='Check this out!',
    # This has the
    attrs=item_data
)
我建议迁移到DynamoDB v2界面:boto的DynamoDB v2界面简介
from boto.dynamodb2.table import Table
table = Table('users')
users.put_item(data={'username': 'johndoe', 
                     'first_name': 'John',
                     'last_name': 'Doe'})
| 归档时间: | 
 | 
| 查看次数: | 3513 次 | 
| 最近记录: |