TransactWrite
Performs multiple write operations atomically across up to 100 items. All succeed or all fail. Supports Put, Update, Delete, and ConditionCheck.
Syntax
dynamodb
await docClient.send(new TransactWriteCommand({ TransactItems: [...] }))Example
dynamodb
await docClient.send(new TransactWriteCommand({
TransactItems: [
{
Update: {
TableName: 'MyApp',
Key: { PK: 'PRODUCT#1', SK: 'META' },
UpdateExpression: 'SET stock = stock - :n',
ConditionExpression: 'stock >= :n',
ExpressionAttributeValues: { ':n': 1 },
},
},
{ Put: { TableName: 'MyApp', Item: { PK: 'ORDER#1', SK: 'ITEM#1' } } },
],
}));