I am working on a "Buy/Sell Item" functionality for an rpg game. If I am correct following actions need to happen in a single transaction
- Get player based on
playerIDfrom "Players" table - Check if player has enough gold, if so create new item object
- Write new item object to "Items" table, where owner is based on
pllayerID - Update "Players" table row where owner is
playerID, deduct gold based on item cost
If in above players gold changes while transaction is running or step 3 or 4 fail to execute simultaneously transaction should fail.
I've read the docs and can see that DynamoDB has TransactWriteItems and TransactGetItems which seem to be perfect for this, but are separate. Can I somehow use them in a single transaction?