Sidharth Ramesh
Sidharth Ramesh

Reputation: 726

DynamoDB Transactions: How to use the result of a GetItem in the next PutItem

Is it possible in DynamoDB Transactions to:

  1. Update an item in table A (increment the value of an item to be specific to my scenario)
  2. Use the updated value of the attribute in a PutItem to another table B.

The transaction should preserve atomicity - so they should either succeed or fail as a unit. How can I achieve this?

Upvotes: 1

Views: 1061

Answers (1)

Seth Geoghegan
Seth Geoghegan

Reputation: 5747

You can do this with DynamoDB Transactions.

From the linked docs:

Amazon DynamoDB transactions simplify the developer experience of making coordinated, all-or-nothing changes to multiple items both within and across tables. Transactions provide atomicity, consistency, isolation, and durability (ACID) in DynamoDB, helping you to maintain data correctness in your applications.

DynamoDB transactions give you an all-or-nothing operation that can span across tables. If a single operation in the transaction fails, the entire transaction fails and the operations are not applied to the Databse. This is in contrast to batch operations, which can succeed or fail independently.

Upvotes: 0

Related Questions