In BatchWriteItem we can do only DeleteRequest and PutRequest and DeleteRequest is only about a single key. However, we may want to delete all keys having a specified prefix.
The expensive solution to that problem is to download all the keys of a specific prefix using a key_condition_expression. Then we would issue the corresponding list of DeleteRequest in BatchWriteItem.
Is there a better way? What would be the right way to architecture a DynamoDb database in order to be able to do that?
In DynamoDB to do any sort of Put/Update/Delete you have to know the entire primary key (Partition and Sort key).
For that reason you would need to read the items first to obtain the full key for items which match your filter logic and use BatchWriteItem to delete up to 25 items per batch.