Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading