Skip to main content

Table

Creates and manages DynamoDB tables with support for partition and sort keys, flexible billing modes, and automatic table status monitoring.

Props

partitionKey
object
required
Primary partition key (hash key) configuration. Defines the main identifier for items in the table.
tableName
string
Name of the DynamoDB table.Default: ${app}-${stage}-${id}
sortKey
object
Optional sort key (range key) configuration. Used to sort items with the same partition key.
billingMode
'PROVISIONED' | 'PAY_PER_REQUEST'
Billing mode for the table.
  • PROVISIONED: Set read/write capacity units
  • PAY_PER_REQUEST: Pay per request pricing
readCapacity
number
Read capacity units when using PROVISIONED billing mode.Default: 5
writeCapacity
number
Write capacity units when using PROVISIONED billing mode.Default: 5
tags
Record<string, string>
Tags to apply to the table. Key-value pairs for resource organization.

Output

arn
string
ARN of the table.Format: arn:aws:dynamodb:region:account-id:table/table-name
tableName
string
Name of the DynamoDB Table.
streamArn
string
ARN of the table’s stream if enabled.Format: arn:aws:dynamodb:region:account-id:table/table-name/stream/timestamp
tableId
string
Unique identifier for the table.

Examples

Table with partition and sort key

import { Table } from "alchemy/aws";

const table = await Table("user-events", {
  tableName: "user-events",
  partitionKey: {
    name: "id",
    type: "S"
  },
  sortKey: {
    name: "timestamp",
    type: "N"
  },
  tags: {
    Environment: "test"
  }
});

Table with provisioned capacity

import { Table } from "alchemy/aws";

const table = await Table("high-throughput", {
  tableName: "high-throughput",
  partitionKey: {
    name: "userId",
    type: "S"
  },
  billingMode: "PROVISIONED",
  readCapacity: 100,
  writeCapacity: 50
});

Simple table with partition key only

import { Table } from "alchemy/aws";

const table = await Table("users", {
  partitionKey: {
    name: "id",
    type: "S"
  }
});

Build docs developers (and LLMs) love