Transactions in the DynamoDB node.js DocumentClient with transactWrite and transactGet

Chris Biscardi
InstructorChris Biscardi
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Transactions allow us to guarantee that a set of operations will succeed or fail as a unit. This is different than the behavior of batchWrite and batchGet. Transactions also enable us to use more of the DynamoDB API, such as Update and ConditionCheck.

Instructor: [0:00] TransactGet is a lot like BatchGet. It is a slightly different syntax where we use transact items instead of request items. We have to specify each get separately with the table name.

[0:11] TransactItems cannot use the GSI or a secondary index, so there is no way to specify an index instead of a table name. If we run TransactGet from this script on this table with three items in it, we get back our responses key each of the items.

[0:26] Note that the main difference between TransactGet and BatchGet is that TransactGet will completely fail if anything fails, such as going over the provision to capacity for a table, while BatchGet will get you as much as it can and then give you the unprocessed keys as well.

[0:41] Note that the main difference between TransactWrite and BatchWrite is not only that the entire request will fail or succeed in total, but that we have access to more of the API like update which we didn't have access to before. In this case, we're deleting the first item, putting todo4 for user1 and updating todo2 with a new text value.

[1:00] If we refresh the DynamoDB console and take a look at what happened, we can see that the todo1 is gone because we deleted it successfully. Todo2 has updated its text value inside of the data attribute. We've also put todo4 with an additional value.

[1:15] Note that in addition to put, delete, and update, TransactWrite allows us to specify condition check objects. This allows us to specify a condition expression that is very similar to any of the other condition expressions that we've written. If the condition check fails, the entire write transaction will fail as well.

egghead
egghead
~ 2 hours ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today