Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boto dynamodb batch_write and delete_item -- 'The provided key element does not match the schema'

I'm trying to delete a large number of items in a DynamoDB table using boto and python. My Table is set up with the primary key as a device ID (think MAC address.) There are multiple entries in the table for each device ID, as the secondary key is a UNIX timestamp.

From my reading this code should work:

from boto.dynamodb2.table import Table

def delete_batch(self, guid):    
    table = Table('Integers')

    with table.batch_write() as batch:
        batch.delete_item(Id=guid)

Source: http://docs.pythonboto.org/en/latest/dynamodb2_tut.html#batch-writing

However it returns 'The provided key element does not match the schema' as the error message.

I suspect the problem is because guid is not unique in my table.

Given that, is there way to delete multiple items with the same primary key without specifying the secondary key?

like image 939
Matt Manuel Avatar asked Mar 20 '23 13:03

Matt Manuel


1 Answers

You are providing only the hash part of the key and not an item (hash+range) - this is why you get an error and can't delete items.

You can't ask DynamoDB to delete all items with a hash key (the same way Query gets them all)

Read this answer by Steffen for more information

like image 190
Chen Harel Avatar answered Apr 07 '23 00:04

Chen Harel