0
0
DynamoDBquery~20 mins

Transaction conditions in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Transaction Conditions Master
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 DynamoDB transaction condition?

Consider a DynamoDB transaction that includes a ConditionCheck on a table Users with the condition attribute_exists(UserID). The transaction tries to update a user with UserID = '123'. What happens if the user does not exist?

DynamoDB
TransactWriteItems: [
  {
    ConditionCheck: {
      TableName: 'Users',
      Key: { UserID: '123' },
      ConditionExpression: 'attribute_exists(UserID)'
    }
  },
  {
    Update: {
      TableName: 'Users',
      Key: { UserID: '123' },
      UpdateExpression: 'SET Age = :newAge',
      ExpressionAttributeValues: { ':newAge': 30 }
    }
  }
]
AThe transaction succeeds and creates a new user with UserID '123' and Age 30.
BThe transaction fails with a ConditionalCheckFailedException because the user does not exist.
CThe transaction ignores the condition and updates the user if it exists.
DThe transaction partially succeeds by updating the user but skips the condition check.
Attempts:
2 left
💡 Hint

Think about what attribute_exists means in a condition check.

📝 Syntax
intermediate
2:00remaining
Which option correctly uses a transaction condition to ensure an item attribute equals a value?

You want to update a DynamoDB item only if its Status attribute equals 'Pending'. Which transaction condition syntax is correct?

AConditionExpression: "Status = 'Pending'"
BConditionExpression: "attribute_not_exists(Status) OR Status = 'Pending'"
CConditionExpression: "attribute_exists(Status) AND Status = :status", ExpressionAttributeValues: { ':status': 'Pending' }
DConditionExpression: "Status == 'Pending'"
Attempts:
2 left
💡 Hint

Remember to use expression attribute values for string comparisons in DynamoDB conditions.

optimization
advanced
2:00remaining
How to optimize a transaction condition to reduce read capacity usage?

You have a transaction that updates an item only if its Version attribute matches a given number. You want to minimize read capacity units consumed by the condition check. Which approach is best?

AUse a <code>ConditionExpression</code> in the <code>Update</code> operation with <code>Version = :v</code> to check atomically.
BUse a <code>ConditionCheck</code> with <code>Version = :v</code> in the transaction to verify before update.
CPerform a separate <code>GetItem</code> before the transaction to check the version, then run the transaction without conditions.
DSkip the condition and rely on eventual consistency to handle conflicts.
Attempts:
2 left
💡 Hint

Think about how DynamoDB transactions handle conditions inside update operations.

🔧 Debug
advanced
2:00remaining
Why does this DynamoDB transaction fail with a ConditionalCheckFailedException?

Given this transaction snippet:

TransactWriteItems: [
  {
    Update: {
      TableName: 'Orders',
      Key: { OrderID: 'A1' },
      UpdateExpression: 'SET Status = :newStatus',
      ConditionExpression: 'Status = :expectedStatus',
      ExpressionAttributeValues: {
        ':newStatus': 'Shipped',
        ':expectedStatus': 'Processing'
      }
    }
  }
]

The transaction fails with ConditionalCheckFailedException. What is the most likely reason?

AThe current <code>Status</code> attribute value is not 'Processing', so the condition fails.
BThe <code>ExpressionAttributeValues</code> are missing a required value for <code>:Status</code>.
CThe <code>UpdateExpression</code> syntax is invalid and causes the failure.
DThe <code>Key</code> does not match any item, so the update fails silently.
Attempts:
2 left
💡 Hint

Check the condition expression and the current item state.

🧠 Conceptual
expert
2:00remaining
What is the atomic behavior of DynamoDB transactions with multiple condition checks?

You have a DynamoDB transaction with multiple ConditionCheck operations on different items. What happens if one condition fails?

AThe transaction partially commits all operations before the failed condition.
BDynamoDB retries the transaction automatically until all conditions pass.
COnly the failed condition check is skipped; other operations proceed.
DThe entire transaction fails and none of the writes or updates are applied.
Attempts:
2 left
💡 Hint

Recall the atomicity guarantees of DynamoDB transactions.