Search code examples
amazon-web-servicesamazon-dynamodb

DynamoDb delete non-existent item does not fail, why?


I am deleting a non-existing record from the dynamodb table using dynamoDbMapper.delete(object) which uses default DynamoDBDeleteExpression

I was expecting some sort of exception to arise since the record is absent from the DB but it does nothing. It does not even have a return type which could tell if the delete was successful or failure. Is there a way to add a delete expression or something which will make my delete throw an exception if the item is absent from the db?


Solution

  • It is by design:

    Unless you specify conditions, the DeleteItem is an idempotent operation; running it multiple times on the same item or attribute does not result in an error response.

    FROM: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html