Inserting None values into DynamoDB using Boto

You are not doing anything wrong. While boto is sophisticated indeed, you have to remember, that it does not have the knowledge of your business logic.

For example, there are at least a few ways someone can think of saving None to DynamoDB database:

  • as "None" string
  • as empty string
  • don't save at all - remember, it is NoSQL database, attributes are not required

The best way to determine it - is your code. If your data could be None, don't add it to the dictionary.


Attribute values in DynamoDB can be neither empty strings nor empty sets. While I discovered this empirically, the most direct reference I see to this is here:

http://awsdocs.s3.amazonaws.com/dynamodb/latest/dynamodb-dg.pdf

So the second bullet suggested by the approved answer will not work.

The third bullet of the accepted answer is the best approach, as implied by the accepted answer. From a design perspective, it more closely aligns with the NoSql paradigm and will likely provide some degree of efficiency over attempting to identify for each data type a None/NULL representation and storing it. This paradigm then manifests itself in your logic as checking existence/membership of the key (if/then or try/except, depending on the scenario) as opposed to checking the key for a "None/NULL equivalent" value.

If you truly seek to store attributes with a value that you equate to NULL/None, I'd recommend establishing a unique/proprietary value for accomplishing this within your application, something more identifiable than, in the case of a string, just 'None'.

(I'd rather have simply commented on the existing answer, but my status as a new user on stackoverflow evidently prevents me from doing so...hope this wasn't poor etiquette...)


Update - May 2020
AWS update DynamoDB supports Null and empty objects

As per this update -

Amazon DynamoDB now supports empty values for non-key String and Binary attributes in DynamoDB tables. Empty value support gives you greater flexibility to use attributes for a broader set of use cases without having to transform such attributes before sending them to DynamoDB. List, Map, and Set data types also support empty String and Binary values.

Partition key and sort key attributes of base tables continue to require non-empty values for all data types, including String and Binary. Similarly, String and Binary key attributes of local secondary indexes or global secondary indexes also require non-empty values.

To put null attribute use type "NULL" and value as True.

Python: AttributeUpdates["MyNull"] = {'Value': {'NULL': True}, 'Action': 'PUT'}

To put empty String attribute use type "S" and value as "".

Python: AttributeUpdates["MyEmptyString"] = {'Value': {'S': ""}, 'Action': 'PUT'}

This will be a valid dynamoDB put_item payload. More details - API_PutItem