Search code examples
amazon-web-servicesamazon-dynamodb

Remove item from DynamoDB with composite sorting key


I have a composite sorting key "123#abc" and I want to remove the item starting with "123".
I can query with such a prefix but I didn't find how to delete an item using a prefix.
AWS doc says I need to provide both partition and sorting keys.
Is it possible to remove an item using a prefix of sort key?

I can query for exact sorting key before removal but I'm curious if delete operation supports this.


Solution

  • Unfortunately its not supported, for a singleton operations such as DeleteItem, GetItem, PutItem etc... you must know the entire primary key, that is Partition and Sort keys (if a sort key exists).

    The only option is to read using Query, then loop the results and call DeleteItem with the keys obtained.