pythonamazon-dynamodbboto3

Float types are not supported. Use Decimal types instead


I'm using Python 3.7 to store data in a DynamoDB database and encountering the following error message when I try and write an item to the database:

Float types are not supported. Use Decimal types instead.

My code:

ddb_table = my_client.Table(table_name)

with ddb_table.batch_writer() as batch:
    for item in items:
        item_to_put: dict = json.loads(json.dumps(item), parse_float=Decimal)

        # Send record to database.
        batch.put_item(Item=item_to_put)

"items" is a list of Python dicts.

If I print out the types of the "item_to_put" dict, they are all of type str.


Solution

  • Ran into the same issue and it turned out that Python was passing a string parameter as something else. The issue went away when I wrapped all of the items in str().

    Example from comment:

    item_to_put: dict = {} 
    for item_key in item: 
        item_to_put[item_key] = str(item[item_key])