Updates fail with `ConditionalCheckFailedException: The conditional request failed`. Is it a bug?
IntermediateTroubleshootingRDS, Aurora and DynamoDB
Answer
Likely causes → Usually it is working as designed: the ConditionExpression (for example, an optimistic lock on version, or attribute_not_exists(pk)) was false because another writer changed the item first, or the item already exists.
Diagnose →
aws dynamodb get-item --table-name orders --key '{"orderId":{"S":"o-1001"}}' --consistent-read
aws dynamodb update-item --table-name orders --key '{"orderId":{"S":"o-1001"}}' \
--update-expression 'SET #s=:s, version=version+:one' --condition-expression 'version=:v' \
--expression-attribute-names '{"#s":"status"}' \
--expression-attribute-values '{":s":{"S":"PAID"},":v":{"N":"3"},":one":{"N":"1"}}' \
--return-values-on-condition-check-failure ALL_OLD
Fix →
- Treat it as a conflict: re-read, merge, and retry with the new version
- Use
ReturnValuesOnConditionCheckFailure=ALL_OLDto see the current item without a second read
Prevent → Handle the exception explicitly in code, and count it as a business metric, not an error.
More on RDS, Aurora and DynamoDB
The app cannot connect to RDS: `psql: error: connection to server at "mydb.abc.us-east-1.rds.amazonaws.com" (10.0.3.12), port 5432 failed: Connection timed out`.Beginner`FATAL: password authentication failed for user "postgres"` and nobody knows the master password.Beginner`FATAL: no pg_hba.conf entry for host "10.0.1.25", user "app", database "orders", no encryption`.IntermediateApp logs show `FATAL: remaining connection slots are reserved for non-replication superuser connections` (or MySQL `ERROR 1040 (HY000): Too many connections`).IntermediateRDS status shows `storage-full` and writes fail.IntermediateA read replica's `ReplicaLag` keeps growing and reports show stale data.Intermediate