# 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`
- **Domain:** aws
- **Category:** data_error
- **Error Code:** `TransactionCanceledException`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| DynamoDB API 2012-08-10 | active | — | — |
| AWS SDK v2.21.0 | active | — | — |

## Workarounds

1. **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']`** (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']`
   ```
2. **Use DynamoDB Streams to capture pre-image and verify condition logic offline before retrying.** (70% success)
   ```
   Use DynamoDB Streams to capture pre-image and verify condition logic offline before retrying.
   ```
3. **Simplify transaction: reduce number of items per transaction or split into individual PutItem/UpdateItem calls with retry logic.** (75% success)
   ```
   Simplify transaction: reduce number of items per transaction or split into individual PutItem/UpdateItem calls with retry logic.
   ```

## Dead Ends

- **Retry the transaction with exponential backoff without checking conditions** — Retrying a transaction with a failing condition will keep failing; the condition must be fixed first. (95% fail)
- **Increase DynamoDB write capacity units** — Throughput is not the issue; this is a condition check failure, not a throttling error. (85% fail)
- **Ignore cancellation reasons and assume transient error** — Cancellation reasons like 'ConditionalCheckFailed' indicate a specific logic error that must be addressed. (90% fail)
