ConditionalCheckFailedException
aws
data_error
ai_generated
true
调用 PutItem 操作时发生错误 (ConditionalCheckFailedException):条件请求失败
An error occurred (ConditionalCheckFailedException) when calling the PutItem operation: The conditional request failed
ID: aws/dynamodb-conditional-check-failed
90%修复率
89%置信度
1证据数
2023-03-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| DynamoDB 2012-08-10 | active | — | — | — |
| AWS SDK for Python 1.33.0 | active | — | — | — |
| AWS CLI 2.14.0 | active | — | — | — |
根因分析
DynamoDB PutItem 上的条件表达式(例如 attribute_not_exists)评估为 false,意味着项目已存在或条件未满足。
English
A conditional expression on a DynamoDB PutItem (e.g., attribute_not_exists) evaluated to false, meaning the item already exists or a condition was not met.
官方文档
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.ConditionalUpdate解决方案
-
在 PutItem 之前使用 GetItem 调用检查项目的当前状态,并相应调整条件表达式(例如,仅在项目应为新项目时使用 attribute_not_exists)。
-
使用带有条件表达式的 UpdateItem 来检查预期状态,或使用 TransactWriteItems 中的事务以原子方式处理冲突。
无效尝试
常见但无效的做法:
-
Retry the PutItem operation with the same condition.
95% 失败
The condition still fails because the underlying data hasn't changed.
-
Remove all conditions from the PutItem call.
70% 失败
This bypasses the intended logic, potentially causing duplicate records or data corruption.
-
Increase the read/write capacity of the table.
85% 失败
Throughput is not the issue; it's a logical condition failure.