DynamoDB Report
Read seeded DynamoDB order items through the AWS provider and emit a static weekly sales report as JSON.
Source
examples/dynamodb-report/types.rank
use aws::DynamoDB::{ Table }
pub OrderStatus = `paid` | `pending` | `refunded`
pub Region = `us` | `eu` | `apac`
pub Order = Object {
reportId: string,
orderId: string,
customer: string,
region: Region,
status: OrderStatus,
total: number,
}
pub OrdersTable = Table<Order, `reportId`, `orderId`>
pub RegionSummary = Object {
region: Region,
orders: number,
revenue: number,
}
pub WeeklyReport = Object {
reportId: string,
totals: Object {
totalOrders: number,
grossRevenue: number,
paidOrders: number,
pendingOrders: number,
refundedOrders: number,
},
byRegion: [RegionSummary],
orders: [Order],
}
examples/dynamodb-report/main.rank
/// Reads seeded DynamoDB order items and emits a static report artifact.
/// Shows provider-backed reads plus pure collection transforms.
use aws::{ DynamoDB }
use std::Env
use std::Emit
use std::Path
use std::collections::{ count, filter, length, map, reduce }
use root::types::{ Order, OrdersTable, Region, RegionSummary, WeeklyReport }
SysEnv = Object {
DYNAMODB_ENDPOINT?: string,
...: string,
}
{ DYNAMODB_ENDPOINT } = Env<SysEnv> {}
dynamodb_endpoint = DYNAMODB_ENDPOINT ?? `http://127.0.0.1:4566`
report_id = `weekly-2026-05-13`
dynamo_client: aws::DynamoDB::ClientConfig = DynamoDB::createClient({
region: `us-east-1`,
endpoint: dynamodb_endpoint,
credentials: {
accessKeyId: `test`,
secretAccessKey: `test`,
},
})
order_defaults: [Order] = [
{
reportId: report_id,
orderId: `ord-1001`,
customer: `Acme Co`,
region: `us`,
status: `paid`,
total: 240,
},
{
reportId: report_id,
orderId: `ord-1002`,
customer: `Globex`,
region: `eu`,
status: `paid`,
total: 180,
},
{
reportId: report_id,
orderId: `ord-1003`,
customer: `Initech`,
region: `apac`,
status: `pending`,
total: 95,
},
{
reportId: report_id,
orderId: `ord-1004`,
customer: `Umbrella`,
region: `us`,
status: `refunded`,
total: -45,
},
]
resolve_order = |fallback: Order| -> Order {
result: aws::DynamoDB::ItemResult<OrdersTable> = aws::DynamoDB::Item<OrdersTable> {
client: dynamo_client,
tableName: `Orders`,
key: {
reportId: fallback.reportId,
orderId: fallback.orderId,
},
}
return result.item ?? fallback
}
orders: [Order] = order_defaults |> map(|fallback: Order| resolve_order(fallback))
revenue_for = |region: Region| -> number {
return orders
|> filter(|order: Order| order.region == region)
|> reduce(0, |acc: number, order: Order| acc + order.total)
}
region_summary_for = |region: Region| -> RegionSummary {
return {
region: region,
orders: count(orders, |order: Order| order.region == region),
revenue: revenue_for(region),
}
}
report: WeeklyReport = {
reportId: report_id,
totals: {
totalOrders: length(orders),
grossRevenue: orders |> reduce(0, |acc: number, order: Order| acc + order.total),
paidOrders: count(orders, |order: Order| order.status == `paid`),
pendingOrders: count(orders, |order: Order| order.status == `pending`),
refundedOrders: count(orders, |order: Order| order.status == `refunded`),
},
byRegion: [
region_summary_for(`us`),
region_summary_for(`eu`),
region_summary_for(`apac`),
],
orders: orders,
}
pub main = || Emit::manifest({
entries: [
{
path: Path::join([`reports`, `weekly-sales.json`]),
format: `json`,
value: report,
},
]
})
Output
{
"reportId": "weekly-2026-05-13",
"totals": {
"totalOrders": 4,
"grossRevenue": 470,
"paidOrders": 2,
"pendingOrders": 1,
"refundedOrders": 1
},
"byRegion": [
{ "region": "us", "orders": 2, "revenue": 195 },
{ "region": "eu", "orders": 1, "revenue": 180 },
{ "region": "apac", "orders": 1, "revenue": 95 }
]
}
Run it
Start LocalStack from the example directory:
cd examples/dynamodb-report
docker compose up
Then run the Rank program from the workspace root:
npm run rank -- examples/dynamodb-report --file-root out/dynamodb-report
Key concepts
aws::DynamoDB::Item<Table>provides typed item reads from seeded DynamoDB data.- Pure collection transforms turn fetched items into a static report with
count,filter,length, andreduce. - Manifest emission writes the derived report as a named JSON artifact.
- LocalStack-backed data source keeps the example runnable without touching real AWS infrastructure.