Database Component
Provisions a serverless NoSQL database with one or more tables. Each provider maps to its native serverless database offering. Table definitions are provider-agnostic — the plugin translates them to the appropriate key schema for DynamoDB, Cosmos DB, or Firestore.
Configuration Fields
Field | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | required | — | Must be "database" |
name | string | required | — | Unique component name. |
tables | array | required | — | One or more table definitions. Each table must have a unique name within the component. |
billingMode | string | optional | "PAY_PER_REQUEST" | Billing mode. "PAY_PER_REQUEST" (on-demand) or "PROVISIONED". AWS only. |
pointInTimeRecovery | boolean | optional | false | Enable point-in-time recovery. Recommended for production. |
Table Definition
Field | Type | Required | Description |
|---|---|---|---|
name | string | required | Unique table name within the database component. Used as suffix in the derived cloud resource name. |
partitionKey | object | required | The primary partition key definition. |
partitionKey.name | string | required | Attribute name for the partition key. |
partitionKey.type | string | required | Key type: "string", "number", or "binary". |
sortKey | object | optional | Optional sort key definition. Omit for partition-key-only tables. |
sortKey.name | string | required (if sortKey present) | Attribute name for the sort key. |
sortKey.type | string | required (if sortKey present) | Key type: "string", "number", or "binary". |
ttlAttribute | string | optional | Enables DynamoDB Time To Live using the named item attribute (epoch-seconds expiry). Items without the attribute never expire. See Time To Live below. (AWS) |
Key types are provider-agnostic. The plugin maps them as follows:
- AWS (DynamoDB): string → S, number → N, binary → B
- Azure (Cosmos DB): The partition key path is derived from the partitionKey.name
- GCP (Firestore): The document ID field is set to partitionKey.name
Cloud Resources Created
- DynamoDB Table — named {derived-name}. On-demand billing by default.
- SSE — server-side encryption with AWS-managed keys enabled by default.
- Time To Live (only when a table declares a ttlAttribute) — DynamoDB TTL is enabled on that attribute so items are auto-deleted after their expiry timestamp. Removed with the table on undeploy.
Limitations: DynamoDB is a key-value / document store. Relational queries require careful data modelling. Global secondary indexes are not configured by the plugin.
- Cosmos DB Account — SQL (Core) API, strong consistency, provisioned via azure-resourcemanager-cosmos. Named {derived-name} (lowercased). Creation is idempotent — an already-existing account is treated as success.
- Cosmos DB Database — named {derived-name}-db.
- Cosmos DB Container — named data with the configured partition key.
Limitations: Cosmos DB account names must be globally unique and ≤ 44 characters (lowercase letters, digits and hyphens).
- Firestore Database — native mode, named (default) (one per project). If a Firestore database already exists in the project, the plugin uses it.
Limitations: Only one Firestore database per GCP project in native mode. All database components in a GCP project share the same Firestore instance.
Time To Live (TTL) (AWS)
Set ttlAttribute on a table to enable DynamoDB Time To Live. DynamoDB then automatically deletes each item shortly after the epoch-seconds timestamp stored in that attribute — a delete-only, no-cost background process that keeps table size and cost bounded without a bespoke scan.
Items without the attribute never expire. This is native DynamoDB behaviour: TTL only acts on items that carry the attribute. So you can exempt specific items from expiry simply by writing them without the TTL attribute (e.g. keep direct messages forever while ageing out group chat).
Example
{
"type": "database",
"name": "ChatMessage",
"providerSettings": {
"tables": [
{
"name": "ChatMessage",
"partitionKey": { "name": "chatId", "type": "string" },
"sortKey": { "name": "ts", "type": "string" },
"ttlAttribute": "expireAt"
}
]
}
}
Write expireAt (epoch seconds) on items you want to age out, and omit it on items that should persist. DynamoDB removes expired items within ~48 hours of the timestamp.
Declarative redeploy: the plugin reconciles TTL on every deploy — it enables TTL on the named attribute if it isn't already, re-points it if the attribute changed, and disables TTL if you remove ttlAttribute. Enabling requires dynamodb:DescribeTimeToLive and dynamodb:UpdateTimeToLive on the deploy identity (see Credentials). Note DynamoDB rate-limits TTL toggles (roughly one change per hour per table). TTL is AWS-only; the field is ignored on Azure and GCP.
JSON Example
{
"type": "database",
"name": "app-db",
"providerSettings": {
"tables": [
{
"name": "users",
"partitionKey": { "name": "userId", "type": "string" }
},
{
"name": "orders",
"partitionKey": { "name": "orderId", "type": "string" },
"sortKey": { "name": "createdAt", "type": "number" }
},
{
"name": "sessions",
"partitionKey": { "name": "sessionId", "type": "string" },
"sortKey": { "name": "expiresAt", "type": "number" }
}
],
"billingMode": "PAY_PER_REQUEST",
"pointInTimeRecovery": true
}
}
Minimal Example (single table)
{
"type": "database",
"name": "user-store",
"providerSettings": {
"tables": [
{
"name": "users",
"partitionKey": { "name": "id", "type": "string" }
}
]
}
}
References
Database is a target-only component.