Skip to content

Instantly share code, notes, and snippets.

@clodal
Created December 12, 2020 15:40
Show Gist options
  • Save clodal/6f10ea2023b32e99b3fd11dae03b2b0f to your computer and use it in GitHub Desktop.
Save clodal/6f10ea2023b32e99b3fd11dae03b2b0f to your computer and use it in GitHub Desktop.
Dynamo DB Transactions

Rules of transactions:

  1. You cannot have more than one operation in your transaction for a single item.

  2. You cannot use the results of one operation as an input to another operation in the same transaction.

  3. Aside from the uniqueness of the primary key, there is no enforced dependency (nor enforced non/anti-dependency) between any items in the same table.

  4. There are no dependencies between items in different tables (such as a foreign key requirement) that DynamoDB enforces.

https://stackoverflow.com/questions/56958718/does-the-order-of-operations-in-a-transaction-matter

DynamoDB transaction example for updating Stock when creating Order

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transaction-example.html

DynamoDB transaction example for Checking Credits before making Purchase

https://aws.amazon.com/blogs/aws/new-amazon-dynamodb-transactions/

How to debug your custom VTL resolvers

  1. Do amplify mock
  1. Do $util.error($MY_OBJECT) to view data in the graphql playground

Note: Amplify Mock / DynamoDB Local does not support Transactions

See: https://stackoverflow.com/questions/56708859/dynamodb-transactwriteitems-error-an-unknown-operation-was-requested/56709065

Video about DynamoDB Transactions and common use cases

https://www.youtube.com/watch?v=IgFvWaSQaeg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment