Bird
Raised Fist0
DynamoDBquery~20 mins

TransactWriteItems in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
TransactWriteItems Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the result of this TransactWriteItems operation?
Given a transaction that attempts to put an item and delete another in DynamoDB, what is the outcome if the condition on the delete fails?
DynamoDB
TransactWriteItems({
  TransactItems: [
    {
      Put: {
        TableName: "Users",
        Item: { "UserId": { S: "123" }, "Name": { S: "Alice" } }
      }
    },
    {
      Delete: {
        TableName: "Users",
        Key: { "UserId": { S: "999" } },
        ConditionExpression: "attribute_exists(UserId)"
      }
    }
  ]
})
AThe entire transaction fails and no changes are made because the delete condition is not met.
BThe put operation succeeds but the delete operation fails, so the transaction partially applies.
CThe delete operation is ignored and the put operation succeeds.
DThe transaction retries automatically until the delete condition passes.
Attempts:
2 left
💡 Hint
Remember that TransactWriteItems is atomic; all operations succeed or none do.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this TransactWriteItems request
Which option contains a syntax error that will cause the TransactWriteItems request to fail?
DynamoDB
TransactWriteItems({
  TransactItems: [
    {
      Update: {
        TableName: "Orders",
        Key: { "OrderId": { S: "abc123" } },
        UpdateExpression: "SET #st = :s",
        ExpressionAttributeNames: { "#st": "Status" },
        ExpressionAttributeValues: { ":s": { S: "Shipped" } }
      }
    }
  ]
})
AExpressionAttributeValues key ':s' should be a string without colon.
BKey attribute value should be Number type, not String.
CUpdateExpression uses invalid syntax; should be 'SET Status = :s'.
DMissing comma after ExpressionAttributeNames object.
Attempts:
2 left
💡 Hint
Check punctuation carefully in JSON objects.
❓ optimization
advanced
2:00remaining
Optimizing TransactWriteItems for multiple conditional writes
You want to update 5 items conditionally in a single transaction. Which approach is most efficient and correct?
ASend 5 separate UpdateItem calls with ConditionExpression for each item.
BUse one TransactWriteItems call with 5 Update operations each having its own ConditionExpression.
CUse BatchWriteItem with 5 Put requests and check conditions client-side.
DUse one TransactWriteItems call with 5 Put operations without conditions.
Attempts:
2 left
💡 Hint
TransactWriteItems supports multiple operations atomically with conditions.
🔧 Debug
advanced
2:00remaining
Why does this TransactWriteItems call fail with a TransactionCanceledException?
Given this transaction, why does DynamoDB return TransactionCanceledException with cancellation reasons?
DynamoDB
TransactWriteItems({
  TransactItems: [
    {
      Put: {
        TableName: "Products",
        Item: { "ProductId": { S: "p1" }, "Stock": { N: "10" } },
        ConditionExpression: "attribute_not_exists(ProductId)"
      }
    },
    {
      Update: {
        TableName: "Inventory",
        Key: { "InventoryId": { S: "inv1" } },
        UpdateExpression: "SET Quantity = Quantity - :dec",
        ExpressionAttributeValues: { ":dec": { N: "5" } },
        ConditionExpression: "Quantity >= :dec"
      }
    }
  ]
})
AThe Put operation fails because ProductId 'p1' already exists, causing the transaction to cancel.
BThe Update operation fails because Quantity is less than 5, causing the transaction to cancel.
CThe transaction fails because TransactWriteItems does not support Update operations.
DBoth Put and Update operations fail due to syntax errors in ConditionExpression.
Attempts:
2 left
💡 Hint
Check the condition expressions and existing data state.
🧠 Conceptual
expert
2:00remaining
What is a key benefit of using TransactWriteItems in DynamoDB?
Choose the best description of a key benefit of TransactWriteItems compared to individual write operations.
AIt bypasses all condition checks to speed up writes.
BIt automatically scales throughput for each write operation individually.
CIt guarantees atomicity, so all writes succeed or none do, preventing partial updates.
DIt allows unlimited number of operations in a single transaction.
Attempts:
2 left
💡 Hint
Think about what atomicity means in transactions.

Practice

(1/5)
1. What is the main purpose of TransactWriteItems in DynamoDB?
easy
A. To group multiple write operations into a single atomic transaction
B. To read multiple items from different tables at once
C. To create a backup of the database automatically
D. To perform batch deletes without conditions

Solution

  1. Step 1: Understand the role of TransactWriteItems

    TransactWriteItems groups multiple write actions (Put, Update, Delete) into one atomic transaction.
  2. Step 2: Compare with other options

    It does not perform reads, backups, or unconditional batch deletes.
  3. Final Answer:

    To group multiple write operations into a single atomic transaction -> Option A
  4. Quick Check:

    Atomic transaction = group writes together [OK]
Hint: Remember: TransactWriteItems groups writes atomically [OK]
Common Mistakes:
  • Confusing TransactWriteItems with batch read operations
  • Thinking it automatically backs up data
  • Assuming it only deletes items
2. Which of the following is the correct syntax structure for a TransactWriteItems request in DynamoDB?
easy
A. { TransactWriteItems: [{ Get: { TableName: 'MyTable', Key: {...} } }] }
B. { BatchWriteItems: [{ PutRequest: {...} }, { DeleteRequest: {...} }] }
C. { TransactItems: [{ Put: { TableName: 'MyTable', Item: {...} } }, { Update: {...} }] }
D. { WriteItems: [{ Put: {...} }, { Update: {...} }] }

Solution

  1. Step 1: Identify correct TransactWriteItems syntax

    The correct syntax uses the key 'TransactItems' with an array of actions like Put and Update.
  2. Step 2: Eliminate incorrect options

    BatchWriteItems is a different API; Get is not a write action; WriteItems is not a valid key.
  3. Final Answer:

    { TransactItems: [{ Put: { TableName: 'MyTable', Item: {...} } }, { Update: {...} }] } -> Option C
  4. Quick Check:

    TransactItems with Put/Update = correct syntax [OK]
Hint: Look for 'TransactItems' key with write actions inside [OK]
Common Mistakes:
  • Using BatchWriteItems instead of TransactWriteItems
  • Including Get operations inside TransactWriteItems
  • Using incorrect key names like WriteItems
3. Given the following TransactWriteItems request, what will happen if the condition in the Update action fails?
{
  TransactItems: [
    { Put: { TableName: 'Users', Item: { UserId: '123', Name: 'Alice' } } },
    { Update: { TableName: 'Users', Key: { UserId: '123' }, UpdateExpression: 'SET Age = :age', ConditionExpression: 'attribute_exists(UserId)', ExpressionAttributeValues: { ':age': 30 } } }
  ]
}
medium
A. Put action succeeds; Update action is skipped
B. Both actions succeed regardless of the condition
C. Update action succeeds; Put action is skipped
D. Both Put and Update actions are rolled back; no changes are applied

Solution

  1. Step 1: Understand TransactWriteItems atomicity

    All actions in TransactWriteItems succeed or all fail together as one transaction.
  2. Step 2: Analyze condition failure effect

    If the Update's condition fails, the entire transaction rolls back, including the Put.
  3. Final Answer:

    Both Put and Update actions are rolled back; no changes are applied -> Option D
  4. Quick Check:

    Condition failure rolls back entire transaction [OK]
Hint: If any condition fails, whole TransactWriteItems rolls back [OK]
Common Mistakes:
  • Assuming partial success when condition fails
  • Thinking Put action always succeeds
  • Ignoring atomicity of TransactWriteItems
4. You wrote this TransactWriteItems request but it fails with a syntax error:
{
  TransactItems: [
    { Put: { TableName: 'Orders', Item: { OrderId: '001', Status: 'Pending' } } },
    { Delete: { TableName: 'Orders', Key: { OrderId: '002' } } }
  ],
  ReturnConsumedCapacity: 'TOTAL'
}

What is the likely cause of the error?
medium
A. Delete action requires a ConditionExpression
B. Missing comma after the TransactItems array
C. TransactItems must be an object, not an array
D. TableName cannot be specified inside Put or Delete actions

Solution

  1. Step 1: Check JSON syntax in the request

    ReturnConsumedCapacity is a valid parameter, but the JSON is invalid due to a missing comma after the closing bracket (]) of the TransactItems array.
  2. Step 2: Validate other parts

    Delete and Put actions are correctly structured; TransactItems must be an array; TableName is required inside actions.
  3. Final Answer:

    Missing comma after the TransactItems array -> Option B
  4. Quick Check:

    JSON requires commas between object properties [OK]
Hint: Validate JSON syntax: add commas between top-level properties [OK]
Common Mistakes:
  • Omitting commas in JSON request objects
  • Forgetting TableName inside each action
  • Misusing array vs object for TransactItems
5. You want to atomically update a user's email and delete a related temporary token in DynamoDB using TransactWriteItems. Which of the following request structures correctly achieves this?
hard
A. { TransactItems: [ { Update: { TableName: 'Users', Key: { UserId: 'u1' }, UpdateExpression: 'SET Email = :e', ExpressionAttributeValues: { ':e': 'new@example.com' } } }, { Delete: { TableName: 'Tokens', Key: { TokenId: 't1' } } } ] }
B. { BatchWriteItems: [ { UpdateRequest: { Key: { UserId: 'u1' }, UpdateExpression: 'SET Email = :e' } }, { DeleteRequest: { Key: { TokenId: 't1' } } } ] }
C. { TransactItems: [ { Put: { TableName: 'Users', Item: { UserId: 'u1', Email: 'new@example.com' } } }, { Delete: { TableName: 'Tokens', Key: { TokenId: 't1' } } } ] }
D. { TransactItems: [ { Update: { TableName: 'Users', Key: { UserId: 'u1' }, UpdateExpression: 'SET Email = :e' } }, { Delete: { TableName: 'Tokens', Key: { TokenId: 't1' } } } ], ReturnValuesOnConditionCheckFailure: 'ALL_OLD' }

Solution

  1. Step 1: Identify correct atomic update and delete

    { TransactItems: [ { Update: { TableName: 'Users', Key: { UserId: 'u1' }, UpdateExpression: 'SET Email = :e', ExpressionAttributeValues: { ':e': 'new@example.com' } } }, { Delete: { TableName: 'Tokens', Key: { TokenId: 't1' } } } ] } uses TransactWriteItems with Update and Delete actions correctly structured.
  2. Step 2: Eliminate incorrect options

    { BatchWriteItems: [ { UpdateRequest: { Key: { UserId: 'u1' }, UpdateExpression: 'SET Email = :e' } }, { DeleteRequest: { Key: { TokenId: 't1' } } } ] } uses BatchWriteItems which does not support Update; { TransactItems: [ { Put: { TableName: 'Users', Item: { UserId: 'u1', Email: 'new@example.com' } } }, { Delete: { TableName: 'Tokens', Key: { TokenId: 't1' } } } ] } uses Put which replaces entire item, not update; { TransactItems: [ { Update: { TableName: 'Users', Key: { UserId: 'u1' }, UpdateExpression: 'SET Email = :e' } }, { Delete: { TableName: 'Tokens', Key: { TokenId: 't1' } } } ], ReturnValuesOnConditionCheckFailure: 'ALL_OLD' } includes unsupported parameter ReturnValuesOnConditionCheckFailure.
  3. Final Answer:

    { TransactItems: [ { Update: { TableName: 'Users', Key: { UserId: 'u1' }, UpdateExpression: 'SET Email = :e', ExpressionAttributeValues: { ':e': 'new@example.com' } } }, { Delete: { TableName: 'Tokens', Key: { TokenId: 't1' } } } ] } -> Option A
  4. Quick Check:

    Use Update and Delete inside TransactItems for atomic changes [OK]
Hint: Use Update and Delete inside TransactItems for atomic writes [OK]
Common Mistakes:
  • Using BatchWriteItems for updates
  • Using Put instead of Update to change attributes
  • Adding unsupported parameters in TransactWriteItems
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard