TransactionCanceledException aws data_error ai_generated true

An error occurred (TransactionCanceledException) when calling the TransactWriteItems operation: Transaction cancelled, please refer cancellation reasons for specific details [ConditionalCheckFailed, None]

ID: aws/dynamodb-transaction-canceled

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
1Evidence
2024-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
DynamoDB API 2012-08-10 active
AWS SDK v2.21.0 active

Root Cause

A condition expression on one or more items in the DynamoDB transaction failed, causing the entire transaction to roll back.

generic

中文

DynamoDB 事务中一个或多个项目的条件表达式失败,导致整个事务回滚。

Official Documentation

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-apis.html

Workarounds

  1. 85% success Parse the cancellation reasons array from the error. For each item, check the condition expression logic. Example in Python: `error.response['Error']['Code'] == 'TransactionCanceledException' and 'ConditionalCheckFailed' in error.response['Error']['Message']`
    Parse the cancellation reasons array from the error. For each item, check the condition expression logic. Example in Python: `error.response['Error']['Code'] == 'TransactionCanceledException' and 'ConditionalCheckFailed' in error.response['Error']['Message']`
  2. 70% success Use DynamoDB Streams to capture pre-image and verify condition logic offline before retrying.
    Use DynamoDB Streams to capture pre-image and verify condition logic offline before retrying.
  3. 75% success Simplify transaction: reduce number of items per transaction or split into individual PutItem/UpdateItem calls with retry logic.
    Simplify transaction: reduce number of items per transaction or split into individual PutItem/UpdateItem calls with retry logic.

中文步骤

  1. 从错误中解析取消原因数组。对于每个项目,检查条件表达式逻辑。Python 示例:`error.response['Error']['Code'] == 'TransactionCanceledException' and 'ConditionalCheckFailed' in error.response['Error']['Message']`
  2. 使用 DynamoDB Streams 捕获前镜像,并在重试前离线验证条件逻辑。
  3. 简化事务:减少每个事务的项目数,或拆分为单独的 PutItem/UpdateItem 调用并添加重试逻辑。

Dead Ends

Common approaches that don't work:

  1. Retry the transaction with exponential backoff without checking conditions 95% fail

    Retrying a transaction with a failing condition will keep failing; the condition must be fixed first.

  2. Increase DynamoDB write capacity units 85% fail

    Throughput is not the issue; this is a condition check failure, not a throttling error.

  3. Ignore cancellation reasons and assume transient error 90% fail

    Cancellation reasons like 'ConditionalCheckFailed' indicate a specific logic error that must be addressed.