2015-11-26 34 views
0

我有以下嘗試將項目存儲到DynamoDB中的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

我能夠使用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' 
    } 
}) 

enter image description here