How to store binary data in Dynamo with boto?

amazon-dynamodb, boto

Solution

It needs to be base 64 encoded into a string.

from base64 import b64encode
data = {'B': b64encode(binary_data)}

There is a library that can do this for you: PynamoDB. The code which handles serialization to and from binary for Python 2 and 3 can be found here.

Disclaimer: I am the author of PynamoDB.

Problem

I can't determine from the docs/examples how to store/read binary data from DynamoDB using boto's dynamodb2. How is it done? My guess was with an item value like `{ 'B': binary-data }` but that causes an error in the JSON encoder.

Original source