Updating items in DynamoDB has two special cases - Conditional Operations and Atomic Counters.
Conditional Operations and Expressions
By default, the DynamoDB write operations (PutItem, UpdateItem, DeleteItem) are unconditional: each of these operations will overwrite an existing item that has the specified primary key. In certain cases such as multiple users attempting to modify the same item, this might create problems.
With conditional operations, you can specify a condition that must be satisfied for a put, update, or delete operation to be completed. Conditional operations allow users to implement optimistic concurrency control systems on DynamoDB.
A ConditionExpression can combine multiple conditional clauses, including nested clauses. A ConditionExpression is constructed from the following:
-
Boolean functions: ATTRIBUTE_EXIST, CONTAINS, and BEGINS_WITH
-
Comparison operators: =, <>, <, >, <=, >=, BETWEEN, and IN
-
Logical operators: NOT, AND, and OR.
You can specify an expression as part of the Query API call to filter results based on values of primary keys on a table using the KeyConditionExpression parameter. You can use expressions for both partition and partition-sort keys.
Conditional writes are idempotent. Read more here.
Atomic Counters
You can use the UpdateItem operation to implement an atomic counter—a numeric attribute that is incremented, unconditionally, without interfering with other write requests.
All write requests are applied in the order in which they were received.
With an atomic counter, the updates are not idempotent. In other words, the numeric value will increment each time you call UpdateItem.
Read more here.
- heartin's blog
- Log in or register to post comments
Recent comments