TransactGetItems lets you get multiple items from DynamoDB in one request. It helps you read several records together safely and quickly.
0
0
TransactGetItems in DynamoDB
Introduction
You want to fetch details of multiple orders at once from your database.
You need to get user profiles and their settings in a single call.
You want to read related items from different tables together.
You want to make sure all requested items exist before processing.
You want to reduce the number of separate requests to DynamoDB.
Syntax
DynamoDB
TransactGetItems {
TransactItems: [
{
Get: {
TableName: "TableName",
Key: { "PrimaryKeyName": { "S": "PrimaryKeyValue" } }
}
},
...
]
}You list each item you want to get inside the TransactItems array.
Each item specifies the table and the key to identify the record.
Examples
This example fetches one user with ID 123 and one order with ID abc in a single request.
DynamoDB
TransactGetItems {
TransactItems: [
{
Get: {
TableName: "Users",
Key: { "UserId": { "S": "123" } }
}
},
{
Get: {
TableName: "Orders",
Key: { "OrderId": { "S": "abc" } }
}
}
]
}This example fetches one product with ID p001.
DynamoDB
TransactGetItems {
TransactItems: [
{
Get: {
TableName: "Products",
Key: { "ProductId": { "S": "p001" } }
}
}
]
}Sample Program
This command uses AWS CLI to get a user with ID 'user123' and an order with ID 'order456' together.
DynamoDB
aws dynamodb transact-get-items --transact-items '[
{
"Get": {
"TableName": "Users",
"Key": { "UserId": { "S": "user123" } }
}
},
{
"Get": {
"TableName": "Orders",
"Key": { "OrderId": { "S": "order456" } }
}
}
]'OutputSuccess
Important Notes
TransactGetItems can get up to 100 items in one call.
All items are read atomically, so you get a consistent snapshot.
The request succeeds even if some items are missing; missing items return a null Item object.
Summary
Use TransactGetItems to read multiple items from DynamoDB in one atomic request.
It helps reduce network calls and keeps data consistent.
Specify each item with its table name and key inside the TransactItems list.