Moshe Shaham
Moshe Shaham

Reputation: 15974

Boto3 - delete all items with a specific partition key

I have a table with a partition key and sort key.

I would like to delete all items that belong to a partition key. But when I call delete_item with only the partition key it doesn't work:

table.delete_item(Key={"user_id": "xx"})

I get this error:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the DeleteItem operation: The provided key element does not match the schema

Upvotes: 2

Views: 1696

Answers (1)

Marcin
Marcin

Reputation: 238081

I would like to delete all rows with the partition key "xx"

Not possible. Your key is partition key + sort key, which means that you always have to use both keys to identify your elements. So you have to get the full list of IDs (partition + sort key) and then iterate over them to delete the elements, or use BatchWriteItem for one API call.

Upvotes: 5

Related Questions