Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a DynamoDB item was indeed deleted?

DynamoDB provides an API for deleting items. In the returned DeleteItemOutcome and DeleteItemResult there is no field or method to determine if the key was found and the item was indeed deleted.

The only way to find out if the item was indeed present and deleted, is to request the items' attributes:

new DeleteItemSpec() .withPrimaryKey("key","1") .withReturnValues(ReturnValue.ALL_OLD))

This, however, consumes extra read capacity. Is there a more efficient way to check the delete result - key found and deleted / invalid key?

like image 318
Vladimir Dzhuvinov Avatar asked Sep 28 '17 08:09

Vladimir Dzhuvinov


People also ask

What does the error ProvisionedThroughputExceededException mean in DynamoDB?

ProvisionedThroughputExceededException. Message: You exceeded your maximum allowed provisioned throughput for a table or for one or more global secondary indexes. To view performance metrics for provisioned throughput vs. consumed throughput, open the Amazon CloudWatch console . Example: Your request rate is too high.

How long does it take to delete DynamoDB table?

Dynamo tables tend to be slow on deletes - around 5 minutes is quite normal. The problem is often people want to delete the table and re-create it as cleanup, but this will inject a downtime.

Does DynamoDB PutItem overwrite?

Conditional writes. By default, the DynamoDB write operations ( PutItem , UpdateItem , DeleteItem ) are unconditional: Each operation overwrites an existing item that has the specified primary key.

What is the relationship between an attribute item and table in Amazon DynamoDB?

In DynamoDB, tables, items, and attributes are the core components that you work with. A table is a collection of items, and each item is a collection of attributes. DynamoDB uses primary keys to uniquely identify each item in a table and secondary indexes to provide more querying flexibility.


2 Answers

Try using conditional expressions like

attribute_exists(my_key)

If element doesn't exist conditional check error will be raised

like image 189
Radek Avatar answered Nov 15 '22 17:11

Radek


DeleteItemResult#getAttributes() is the way to determine if a DeleteItem operation has actually deleted an item, or not.

If you specify ReturnValue.ALL_OLD and the item was deleted, a map of item attributes is returned, otherwise and empty map is returned. This is the only way to know for sure if the operation was successful. No other confirmation is returned by the API.

Keep in mind that a DeleteItem operation will consume a minimum of 1 write capacity unit every time. If the deleted item is larger than 1KB, consumed capacity will be more than 1.

For reference: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html#ItemSizeCalculations.Writes

like image 39
albogdano Avatar answered Nov 15 '22 18:11

albogdano