Home > Mobile >  DynamoDB return the modified document (Old or new) when using TransactWrtieItems
DynamoDB return the modified document (Old or new) when using TransactWrtieItems

Time:12-30

Is there a way of making transactWriteItem return the document it updated?

const transactionParams = {
    ReturnConsumedCapacity: "INDEXES",
    TransactItems: [
      {
        Delete: {
          TableName: reactionTableName,
          Key: {
            "SOME_PK_",
            "SOME_SK_",
          },
          ReturnValues: 'ALL_OLD',
        },
      },
      {
        Update: {
          TableName: reviewTableName,
          Key: { PK: "SOME_PK", SK: "SOME_SK" },
          ReturnValues: 'ALL_OLD',
        },
      },
    ],
  };

  try {
    const result = await docClient.transactWrite(transactionParams).promise();
  } catch (error) {
    context.done(error, null);
  }

For example in the above code get the documents that were touched (before or after update)?

CodePudding user response:

No, TransactWriteItems API does not provide the ability to return values of a modified item, however, you could obtain those values using DynamoDB Streams, otherwise you would need to default to the singleton APIs UpdateItem/DeleteItem which are not ACID compliant together.

  • Related