0
0
DynamoDBquery~10 mins

Why transactions ensure atomicity in DynamoDB - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a transaction in DynamoDB.

DynamoDB
const params = { TransactItems: [[1]] };
Drag options to blanks, or click blank then click option'
A{ Put: { TableName: 'MyTable', Item: { id: '123', attribute: 'value' } } }
B{ Get: { TableName: 'MyTable', Key: { id: '123' } } }
C{ Delete: { TableName: 'MyTable', Key: { id: '123' } } }
D{ Update: { TableName: 'MyTable', Key: { id: '123' }, UpdateExpression: 'set #a = :val', ExpressionAttributeNames: { '#a': 'attribute' }, ExpressionAttributeValues: { ':val': 'newValue' } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Get inside TransactItems which is not a write operation.
Forgetting to wrap operations inside TransactItems array.
2fill in blank
medium

Complete the code to execute a transaction using DynamoDB DocumentClient.

DynamoDB
await docClient.[1](params).promise();
Drag options to blanks, or click blank then click option'
AtransactWrite
Bput
Cupdate
DbatchWrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using put or update which perform single operations, not transactions.
Using batchWrite which does not guarantee atomicity.
3fill in blank
hard

Fix the error in the transaction code by choosing the correct option for the condition check.

DynamoDB
ConditionCheck: { TableName: 'MyTable', Key: { id: '123' }, ConditionExpression: '[1]' }
Drag options to blanks, or click blank then click option'
Aid = :val
Battribute_exists(id)
Cattribute_not_exists(id)
Dattribute_type(id, 'S')
Attempts:
3 left
💡 Hint
Common Mistakes
Using attribute_not_exists which checks for absence, causing transaction failure.
Using invalid expressions like id = :val without defining :val.
4fill in blank
hard

Fill both blanks to create a transaction that updates and deletes items atomically.

DynamoDB
const params = { TransactItems: [ { [1]: { TableName: 'Orders', Key: { orderId: '001' }, UpdateExpression: 'set #s = :new', ExpressionAttributeNames: { '#s': 'status' }, ExpressionAttributeValues: { ':new': 'shipped' } } }, { [2]: { TableName: 'Cart', Key: { cartId: 'abc' } } } ] };
Drag options to blanks, or click blank then click option'
AUpdate
BPut
CDelete
DGet
Attempts:
3 left
💡 Hint
Common Mistakes
Using Put instead of Update for modifying existing items.
Using Get which is not a write operation.
5fill in blank
hard

Fill all three blanks to define a transaction that puts, updates, and conditionally checks items atomically.

DynamoDB
const params = { TransactItems: [ { [1]: { TableName: 'Users', Item: { userId: 'u123', name: 'Alice' } } }, { [2]: { TableName: 'Profiles', Key: { profileId: 'p456' }, UpdateExpression: 'set #v = :val', ExpressionAttributeNames: { '#v': 'verified' }, ExpressionAttributeValues: { ':val': true } } }, { ConditionCheck: { TableName: 'Sessions', Key: { sessionId: 's789' }, ConditionExpression: '[3]' } } ] };
Drag options to blanks, or click blank then click option'
APut
BUpdate
Cattribute_exists(sessionId)
DDelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using Delete instead of Put for adding items.
Using a wrong condition expression that does not check attribute existence.