Challenge - 5 Problems
TransactWriteItems Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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)"
}
}
]
})Attempts:
2 left
💡 Hint
Remember that TransactWriteItems is atomic; all operations succeed or none do.
✗ Incorrect
In DynamoDB, TransactWriteItems ensures atomicity. If any condition fails, the entire transaction is rolled back and no changes are applied.
📝 Syntax
intermediate2: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" } }
}
}
]
})Attempts:
2 left
💡 Hint
Check punctuation carefully in JSON objects.
✗ Incorrect
In JSON, commas separate key-value pairs. Missing a comma after ExpressionAttributeNames causes a syntax error.
❓ optimization
advanced2: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?
Attempts:
2 left
💡 Hint
TransactWriteItems supports multiple operations atomically with conditions.
✗ Incorrect
Using one TransactWriteItems call with multiple conditional updates ensures atomicity and efficiency compared to multiple calls or batch writes without conditions.
🔧 Debug
advanced2: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"
}
}
]
})Attempts:
2 left
💡 Hint
Check the condition expressions and existing data state.
✗ Incorrect
If the Put operation's condition attribute_not_exists(ProductId) fails because the item exists, the entire transaction is canceled with reasons.
🧠 Conceptual
expert2: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.
Attempts:
2 left
💡 Hint
Think about what atomicity means in transactions.
✗ Incorrect
TransactWriteItems ensures all operations in the transaction succeed or none do, preventing partial updates and maintaining data integrity.