ConditionalCheckFailedException aws data_error ai_generated true

An error occurred (ConditionalCheckFailedException) when calling the PutItem operation: The conditional request failed

ID: aws/dynamodb-conditional-check-failed

Also available as: JSON · Markdown · 中文
90%Fix Rate
89%Confidence
1Evidence
2023-03-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
DynamoDB 2012-08-10 active
AWS SDK for Python 1.33.0 active
AWS CLI 2.14.0 active

Root Cause

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.

generic

中文

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

Official Documentation

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.ConditionalUpdate

Workarounds

  1. 90% success Check the item's current state using a GetItem call before PutItem, and adjust the condition expression accordingly (e.g., use attribute_not_exists only if item should be new).
    Check the item's current state using a GetItem call before PutItem, and adjust the condition expression accordingly (e.g., use attribute_not_exists only if item should be new).
  2. 85% success Use UpdateItem with a condition expression that checks the expected state, or use a transaction with TransactWriteItems to handle conflicts atomically.
    Use UpdateItem with a condition expression that checks the expected state, or use a transaction with TransactWriteItems to handle conflicts atomically.

中文步骤

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

Dead Ends

Common approaches that don't work:

  1. Retry the PutItem operation with the same condition. 95% fail

    The condition still fails because the underlying data hasn't changed.

  2. Remove all conditions from the PutItem call. 70% fail

    This bypasses the intended logic, potentially causing duplicate records or data corruption.

  3. Increase the read/write capacity of the table. 85% fail

    Throughput is not the issue; it's a logical condition failure.