Transaction request cannot include multiple operations on one item

TL;DR — Two actions in the same TransactWriteItems request target the same item (same primary key). DynamoDB requires every item in a transaction to be unique, so it rejects the whole call before running any of it. Collapse the duplicate actions into one, or move one of them to a separate write.

What it means

ValidationException: Transaction request cannot include multiple operations on one item

A TransactWriteItems request groups up to 100 actions (Put, Update, Delete, ConditionCheck) that all commit or all fail. A hard rule of that API is that no two actions can target the same item — DynamoDB identifies an item by its full primary key, and each key may appear at most once. This is an HTTP 400 ValidationException, caught before the transaction executes, and it is not retryable as-is.

Why it happens

  • A ConditionCheck plus a write on the same key — you tried to assert a condition on an item and also Update/Delete it in the same transaction. Fold the condition into the write's ConditionExpression instead.
  • Two writes to the same key — e.g. a Put and an Update for the same item, often from a loop that doesn't de-duplicate by key.
  • A generated batch with duplicate keys — an ORM or mapping layer emitted the same partition+sort key twice.
  • Same key in two different actions across tables you think are different — the item is uniquely {table, PK, SK}; a repeat within the same table triggers it.

How to fix it

  1. De-duplicate by primary key before building the transaction — each {PK, SK} may appear once.
  2. Merge a ConditionCheck into the write it guards: put the assertion in that item's own ConditionExpression rather than adding a separate ConditionCheck action.
  3. Combine two mutations into one Update using a single UpdateExpression (SET/ADD/REMOVE) instead of two actions.
  4. Split unavoidable multi-step logic across separate transactions or writes if the operations genuinely can't be expressed as one action.

Composing multi-item transactions by hand is where duplicate keys slip in. The DynoTable desktop app shows each item by its primary key so a repeated target is obvious before you send the request.

不必透過主控台就能操作 DynamoDB

DynoTable 是一款快速的 DynamoDB 桌面用戶端 — 瀏覽表格、執行 SQL 風格的查詢,並在本機編輯項目。