Although I introduced you to the Condition expression in the context of PutItem, this concept applies to other API as well. The condition expression must evaluate to true in order for the operation to succeed; otherwise, the operation fails.
The condition expression must evaluate to true in order for the operation to succeed; otherwise, the operation fails. To create the expression you may use:
Example: How to prevent update with PutItem
You can use the function attribute_not_exist(Primary Key) If the attribute exists, it will lead to ConditionCheckFailedException otherwise the item will be created.
aws dynamodb put-item \
--table-name Employee \
--item '{
"LoginAlias": {"S": "irenes"},
"FirstName": {"S": "Irene"},
"LastName": {"S": "Sherwin"},
"ManagerLoginAlias": {"S": "rajs"},
"Designation": {"S": "accountant"},
"Skills": {"SS": ["general accounting"]}
}' \
--condition-expression "attribute_not_exists(LoginAlias)"
Condition expressions is a very powerful idea and is used in multiple scenarios.