TransactionCanceledException aws data_error ai_generated true

调用 TransactWriteItems 操作时出错 (TransactionCanceledException):事务已取消,请参考取消原因了解具体细节 [ConditionalCheckFailed, None]

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

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
1证据数
2024-06-20首次发现

版本兼容性

版本状态引入弃用备注
DynamoDB API 2012-08-10 active
AWS SDK v2.21.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

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

无效尝试

常见但无效的做法:

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

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

  2. Increase DynamoDB write capacity units 85% 失败

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

  3. Ignore cancellation reasons and assume transient error 90% 失败

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