Skip to content

AWS.Keyspaces reference

Source: src/AWS/Keyspaces/Keyspace.ts

An Amazon Keyspaces (for Apache Cassandra) keyspace — the top-level container for Cassandra tables.

Keyspaces are serverless, free to create, and provisioned near-instantly, so they make excellent building blocks and test fixtures.

Basic Keyspace

const keyspace = yield* Keyspace("AppData", {});

Named Keyspace with Tags

const keyspace = yield* Keyspace("AppData", {
keyspaceName: "app_data",
tags: { team: "platform" },
});

Source: src/AWS/Keyspaces/RestoreTable.ts

Runtime binding for cassandra:Restore (the Keyspaces RestoreTable operation).

Bind this operation to a source Table (which must have point-in-time recovery enabled) and a target Keyspace to get a callable that restores the source table’s continuous backup into a new table of the target keyspace, automatically injecting the source keyspace/table and target keyspace names. RestoreTable is asynchronous — the response returns the new table’s ARN while it provisions in the RESTORING state. Provide the RestoreTableHttp layer on the Function to satisfy the binding.

Restore to the Current Time

const restore = yield* AWS.Keyspaces.RestoreTable(sourceTable, keyspace);
const { restoredTableARN } = yield* restore({
targetTableName: "orders_restored",
});

Restore to a Point in Time

const { restoredTableARN } = yield* restore({
targetTableName: "orders_before_incident",
restoreTimestamp: new Date("2026-07-14T12:00:00Z"),
});

Source: src/AWS/Keyspaces/Table.ts

An Amazon Keyspaces (for Apache Cassandra) table.

Tables are serverless and provisioned asynchronously (CREATING -> ACTIVE), usually within a minute; the provider waits for ACTIVE (bounded) before returning. Schema mutations (adding columns, changing capacity/TTL/PITR) are applied in place; changing keys replaces the table.

Simple Key-Value Table

const table = yield* Table("Sessions", {
keyspaceName: keyspace.keyspaceName,
columns: [
{ name: "id", type: "uuid" },
{ name: "data", type: "text" },
],
partitionKeys: ["id"],
});

Table with a Clustering Key and TTL

const table = yield* Table("Events", {
keyspaceName: keyspace.keyspaceName,
columns: [
{ name: "device", type: "text" },
{ name: "ts", type: "timestamp" },
{ name: "payload", type: "blob" },
],
partitionKeys: ["device"],
clusteringKeys: [{ name: "ts", orderBy: "DESC" }],
ttlEnabled: true,
defaultTimeToLive: "1 day",
});
const table = yield* Table("Orders", {
keyspaceName: keyspace.keyspaceName,
columns: [
{ name: "id", type: "uuid" },
{ name: "total", type: "int" },
],
partitionKeys: ["id"],
cdcSpecification: {
status: "ENABLED",
viewType: "NEW_AND_OLD_IMAGES",
},
});
// table.latestStreamArn → consume via the TableStreams binding

Source: src/AWS/Keyspaces/TableStreams.ts

Runtime binding for the Amazon Keyspaces CDC streams data-plane API (cassandra:ListStreams / GetStream / GetShardIterator / GetRecords).

Bind this to a Table whose cdcSpecification is enabled to get a typed client for traversing the table’s change-data-capture stream.

const streams = yield* AWS.Keyspaces.TableStreams(table);
const { streams: available } = yield* streams.listStreams();
const streamArn = available![0].streamArn;
const stream = yield* streams.getStream({ streamArn });
const { shardIterator } = yield* streams.getShardIterator({
streamArn,
shardId: stream.shards![0].shardId!,
shardIteratorType: "TRIM_HORIZON",
});
const { changeRecords } = yield* streams.getRecords({
shardIterator: shardIterator!,
});

Source: src/AWS/Keyspaces/Type.ts

An Amazon Keyspaces (for Apache Cassandra) user-defined type (UDT) — a named group of fields usable as a column type in tables of the same keyspace.

UDTs are immutable: any change to the field definitions replaces the type. A type used by a table (or nested in another type) cannot be deleted until its consumers are gone.

Address Type

const address = yield* Type("Address", {
keyspaceName: keyspace.keyspaceName,
fields: [
{ name: "street", type: "text" },
{ name: "city", type: "text" },
{ name: "zip", type: "text" },
],
});

Use the Type in a Table Column

const table = yield* Table("Customers", {
keyspaceName: keyspace.keyspaceName,
columns: [
{ name: "id", type: "uuid" },
{ name: "shipping", type: `frozen<${address.typeName}>` },
],
partitionKeys: ["id"],
});