MildStack Logo

Amazon DynamoDB

MildStack provides DynamoDB emulation with table management, item operations, queries, scans, secondary indexes, and batch/transaction support.

Overview

MildStack's DynamoDB emulation lets you create tables, store items, and perform queries locally. It supports the standard DynamoDB JSON wire protocol, so your existing AWS SDK code works without changes — just update the endpoint URL.

Supported Operations

Table Operations

OperationDescription
CreateTableCreate a new table with key schema and optional indexes
DescribeTableGet table details (status, key schema, indexes, item count)
ListTablesList all tables
DeleteTableDelete a table and all its items

Item Operations

OperationDescription
PutItemCreate or replace an item
GetItemRetrieve a single item by key
UpdateItemUpdate specific attributes of an item
DeleteItemDelete a single item by key

Query & Scan

OperationDescription
QueryQuery items by partition key with optional sort key conditions
ScanScan all items in a table with optional filters

Batch & Transactions

OperationDescription
BatchGetItemGet multiple items across tables in a single request
BatchWriteItemPut or delete multiple items across tables in a single request
TransactGetItemsRead multiple items atomically
TransactWriteItemsWrite multiple items atomically

Time to Live (TTL)

OperationDescription
UpdateTimeToLiveEnable or disable TTL on a table
DescribeTimeToLiveGet the current TTL configuration

Secondary Indexes

MildStack supports both types of secondary indexes:

  • Global Secondary Indexes (GSI) — Query items by any attribute, across all partitions
  • Local Secondary Indexes (LSI) — Query items by an alternative sort key within a partition

Quick Example

import {
  DynamoDBClient,
  CreateTableCommand,
  PutItemCommand,
  QueryCommand,
} from "@aws-sdk/client-dynamodb";

const client = new DynamoDBClient({
  region: "us-east-1",
  endpoint: "http://localhost:4566",
  credentials: { accessKeyId: "test", secretAccessKey: "test" },
});

// Create a table
await client.send(
  new CreateTableCommand({
    TableName: "Orders",
    KeySchema: [
      { AttributeName: "customerId", KeyType: "HASH" },
      { AttributeName: "orderId", KeyType: "RANGE" },
    ],
    AttributeDefinitions: [
      { AttributeName: "customerId", AttributeType: "S" },
      { AttributeName: "orderId", AttributeType: "S" },
    ],
    BillingMode: "PAY_PER_REQUEST",
  })
);

// Put an item
await client.send(
  new PutItemCommand({
    TableName: "Orders",
    Item: {
      customerId: { S: "cust-123" },
      orderId: { S: "order-001" },
      total: { N: "59.99" },
      status: { S: "shipped" },
    },
  })
);

// Query items for a customer
const result = await client.send(
  new QueryCommand({
    TableName: "Orders",
    KeyConditionExpression: "customerId = :cid",
    ExpressionAttributeValues: {
      ":cid": { S: "cust-123" },
    },
  })
);
console.log(result.Items);

AWS CLI Examples

# Create a table with a GSI
awslocal dynamodb create-table \
  --table-name Products \
  --attribute-definitions \
    AttributeName=id,AttributeType=S \
    AttributeName=category,AttributeType=S \
  --key-schema AttributeName=id,KeyType=HASH \
  --global-secondary-indexes \
    '[{
      "IndexName": "CategoryIndex",
      "KeySchema": [{"AttributeName": "category", "KeyType": "HASH"}],
      "Projection": {"ProjectionType": "ALL"}
    }]' \
  --billing-mode PAY_PER_REQUEST

# Put an item
awslocal dynamodb put-item \
  --table-name Products \
  --item '{
    "id": {"S": "prod-1"},
    "category": {"S": "electronics"},
    "name": {"S": "Wireless Mouse"},
    "price": {"N": "29.99"}
  }'

# Query by GSI
awslocal dynamodb query \
  --table-name Products \
  --index-name CategoryIndex \
  --key-condition-expression "category = :cat" \
  --expression-attribute-values '{":cat": {"S": "electronics"}}'

# Scan with filter
awslocal dynamodb scan \
  --table-name Products \
  --filter-expression "price < :maxPrice" \
  --expression-attribute-values '{":maxPrice": {"N": "50"}}'

Supported Data Types

MildStack supports all DynamoDB attribute types:

TypeCodeExample
StringS{"S": "hello"}
NumberN{"N": "42"}
BooleanBOOL{"BOOL": true}
NullNULL{"NULL": true}
MapM{"M": {"key": {"S": "value"}}}
ListL{"L": [{"S": "a"}, {"N": "1"}]}

Persistence

All DynamoDB data is stored in a local database on your machine. Tables, items, and index data persist across instance restarts. Deleting an instance removes all its DynamoDB data.

On this page