# 调用 PutItem 操作时发生错误 (ConditionalCheckFailedException)：条件请求失败

- **ID:** `aws/dynamodb-conditional-check-failed`
- **领域:** aws
- **类别:** data_error
- **错误码:** `ConditionalCheckFailedException`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

DynamoDB PutItem 上的条件表达式（例如 attribute_not_exists）评估为 false，意味着项目已存在或条件未满足。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| DynamoDB 2012-08-10 | active | — | — |
| AWS SDK for Python 1.33.0 | active | — | — |
| AWS CLI 2.14.0 | active | — | — |

## 解决方案

1. ```
   在 PutItem 之前使用 GetItem 调用检查项目的当前状态，并相应调整条件表达式（例如，仅在项目应为新项目时使用 attribute_not_exists）。
   ```
2. ```
   使用带有条件表达式的 UpdateItem 来检查预期状态，或使用 TransactWriteItems 中的事务以原子方式处理冲突。
   ```

## 无效尝试

- **Retry the PutItem operation with the same condition.** — The condition still fails because the underlying data hasn't changed. (95% 失败率)
- **Remove all conditions from the PutItem call.** — This bypasses the intended logic, potentially causing duplicate records or data corruption. (70% 失败率)
- **Increase the read/write capacity of the table.** — Throughput is not the issue; it's a logical condition failure. (85% 失败率)
