
- attribute_exists
- attribute_not_exists
- attribute_type
- begins_with
- contains
- size
Before using conditional writes, make sure to evaluate your application’s concurrency needs to avoid conflicts when multiple writes occur at the same time.
Attribute Existence Check
Theattribute_exists condition verifies whether a particular attribute exists in an item. For example, to delete an item only if the attribute ProductReviews.OneStar exists, use the following command:
attribute_not_exists to ensure that an operation is executed only when a specified attribute does not exist. The following command deletes the item only if the Price attribute is absent:
Attribute Type Check
Theattribute_type expression ensures that an attribute is of a specific type. For example, if you have an attribute named Color and want to ensure it is stored as a string, execute the following command:
expression-attribute-values.json with the following content:
Color attribute is of type String, the condition evaluates to true, and the delete-item operation is executed.
String Expressions: begins_with and contains
begins_with Expression
Thebegins_with function checks if a string attribute starts with a specific substring. For example, to delete an item only when the attribute Pictures.FrontView begins with "http://", use this command:
expression-attribute-values.json file contains:
contains Expression
Thecontains function determines whether an attribute contains a specified value. For instance, to delete an item if the Color attribute contains "Red", run the following command:
Size Expression
Thesize function evaluates the length or size of an attribute. For example, if you want to delete an item only when the size of the VideoClip attribute is greater than 64,000, you can use this command:
VideoClip attribute exceeds the specified size threshold.
DynamoDB Conditional Writes provide a robust mechanism to safeguard data integrity during concurrent data modifications. By using supported expressions such as
attribute_exists, attribute_not_exists, attribute_type, begins_with, contains, and size, you can ensure write operations occur only when specific conditions are met, thereby preventing unintended data overwrites.