我有以下Python代码尝试将项目存储到DynamoDB中。虽然一切都适用于字符串等,但当我尝试添加字典时它会失败。
该表有一个主要的哈希键,名为"参数"
import boto
from boto.dynamodb import connect_to_region
conn = connect_to_region('eu-west-1')
table = conn.get_table('my-table')
item_dict = {
'Parameter': 'dbparams',
'Value': {
'host': 'myserver',
'user': 'myusername',
'password': 'mypass',
'port': '5555',
},
}
item = table.new_item(attrs=item_dict)
item.put()
这会导致以下错误:
boto.dynamodb.exceptions.DynamoDBValidationError: DynamoDBValidationError: 400 Bad Request
{'__type': 'com.amazon.coral.validate#ValidationException', 'message': 'Supplied AttributeValue is empty, must contain exactly one of the supported datatypes'}
这样做的正确方法是什么?我也无法在Boto文档中找到一个例子。
答案 0 :(得分:0)
我能够使用 boto + dynamodb2 库执行代码。在' port':' 5555'之后,您似乎有一个额外的逗号。 - 你可以摆脱它。我附上了结果的屏幕截图 - 所以你可以看到我得到了什么。希望这会有所帮助。如果您要使用库http://boto.cloudhackers.com/en/latest/dynamodb2_tut.html,请输入以下链接。
import boto.dynamodb2
from boto.dynamodb2.table import Table
#Put in your connection code here and get access to the connection and table objects.
#Once you have your table object..... execute put
table.put_item(data={'Id': 323,
'Parameter': 'dbparams',
'Value': {
'host': 'myserver',
'user': 'myusername',
'password': 'mypass',
'port': '5555'
}
})