4

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?

Matt Manuel
  • 511
  • 1
  • 5
  • 13
  • What is your `Integers` schema? – kukido Feb 17 '14 at 00:30
  • {"Id" : string, "Date" : number, "Temp" : number, "Probenum" : number} Primary Hash Key: Id (String) Primary Range Key: Date (Number) – Matt Manuel Feb 17 '14 at 01:56
  • 1
    Your batch request does not match the schema indeed. Please look at this question for possible solutions:[what-is-the-recomended-way-to-delete-a-large-number-of-items-from-dynamodb](http://stackoverflow.com/questions/9154264/what-is-the-recomended-way-to-delete-a-large-number-of-items-from-dynamodb). – kukido Feb 17 '14 at 02:41

1 Answers1

7

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

Community
  • 1
  • 1
Chen Harel
  • 9,684
  • 5
  • 44
  • 58
  • Thanks. Sounds like I need to make a table for each `guid` and then delete the table when I'm done with it. Too bad DynamoDB doesn't support bulk delete, but I'm sure there's some architectural reason for it. – Matt Manuel Feb 17 '14 at 18:01
  • 1
    Well writes are expensive. bulk writes (deletes) are hard to implement and are also kinda against the dynamodb provisioned approach (which tries to force use to be as predicted as possible). Good luck – Chen Harel Feb 18 '14 at 08:04