Complete the code to start a transaction in DynamoDB.
const params = { TransactItems: [[1]] };Get inside TransactItems which is not a write operation.TransactItems array.The Put operation inside TransactItems starts a transaction to insert or replace an item atomically.
Complete the code to execute a transaction using DynamoDB DocumentClient.
await docClient.[1](params).promise();put or update which perform single operations, not transactions.batchWrite which does not guarantee atomicity.The transactWrite method executes a transaction that ensures all operations succeed or fail together.
Fix the error in the transaction code by choosing the correct option for the condition check.
ConditionCheck: { TableName: 'MyTable', Key: { id: '123' }, ConditionExpression: '[1]' }attribute_not_exists which checks for absence, causing transaction failure.id = :val without defining :val.The condition attribute_exists(id) ensures the item exists before the transaction proceeds, maintaining atomicity.
Fill both blanks to create a transaction that updates and deletes items atomically.
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' } } } ] };Put instead of Update for modifying existing items.Get which is not a write operation.The first operation is an Update to change the order status, and the second is a Delete to remove the cart item, both done atomically.
Fill all three blanks to define a transaction that puts, updates, and conditionally checks items atomically.
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]' } } ] };Delete instead of Put for adding items.The transaction puts a new user, updates a profile, and conditionally checks if a session exists before proceeding, ensuring atomicity.