0
0
DynamoDBquery~20 mins

TransactWriteItems in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 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.