Reputation: 18138
Solution: Updating to the brand-new boto 2.35.2 fixed the problem.
How can I store a dict of dicts in DynamoDB using boto?
The straightforward approach that I've been trying doesn't seem to work. Trying to save an item defined this way:
data = {
'id': '123456',
'foo': {'hello': 'world'}
}
item = Item(my_table, data=data)
item.save(overwrite=True)
generates this exception:
TypeError: Unsupported type "<type 'dict'>" for value "{'hello': 'world'}"
I've seen conflicting information on the web about whether this is supported. I can't get it to work; am using boto 2.35.1.
Here's a complete example that demonstrates the problem:
import boto.dynamodb2
from boto.dynamodb2.fields import HashKey
from boto.dynamodb2.table import Table
from boto.dynamodb2.items import Item
conn = boto.dynamodb2.connect_to_region('us-east-1')
my_table = Table.create('my_table',
connection=conn,
schema=[
HashKey('id')
])
my_table = Table('my_table')
data = {
'id': '123456',
'foo': {'hello': 'world'}
}
item = Item(my_table, data=data)
item.save(overwrite=True)
Upvotes: 0
Views: 851
Reputation: 1161
DynamoDB API now supports map and list object:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataFormat.html
And seams that last boto version (yesterday at the time I answered) added this too:
http://boto.readthedocs.org/en/latest/releasenotes/v2.35.2.html
but personally I didn't play with yet.
Upvotes: 1