Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store binary data in Dynamo with boto?

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.

like image 695
edA-qa mort-ora-y Avatar asked Jan 31 '14 10:01

edA-qa mort-ora-y


People also ask

Can I store binary data in DynamoDB?

You can now store binary data in DynamoDB without having to convert it to a string. You can also store sets composed of binary data. This change will result in greater storage efficiency, along with the potential for lower storage and I/O costs for you.

What is binary data type DynamoDB?

Binary type attributes can store any binary data, such as compressed text, encrypted data, or images. Whenever DynamoDB compares binary values, it treats each byte of the binary data as unsigned.

Can DynamoDB store BLOB data?

Binary large object (BLOB) storage. DynamoDB can store binary items up to 400 KB, but DynamoDB is not generally suited to storing documents or images. A better architectural pattern for this implementation is to store pointers to Amazon S3 objects in a DynamoDB table.


1 Answers

boto provides the Binary class to do this automatically:

from boto.dynamodb2.table import Table
from boto.dynamodb.types import Binary

Table('mytable').put_item({'hashkey': Binary('\x01\x02')})
like image 63
ransomr Avatar answered Sep 27 '22 15:09

ransomr