Skip to content

Convex.aws reference

Source: packages/convex/src/aws/AdminKey.ts

An admin key for a self-hosted Convex backend. Convex.Backend creates one, so most stacks never use this directly.

The key is computed from the name and secret the way the backend’s own generate_key computes it, on the deploying machine. It needs no Docker and no running backend.

This is also what guards the data: a changed instanceName fails the plan with InstanceNameChanged, before anything touches the service, because a new name points the backend at a new, empty database.

Source: packages/convex/src/aws/Backend.ts

Self-hosted Convex on AWS: one Fargate task behind a load balancer, with buckets, TLS and DNS. On its own it owns all of that. Given a shared Convex.Platform, it adds only what’s per stage.

Deploying needs no Docker: the admin key is computed on the deploying machine, and the task pulls the image from its registry through the platform’s NAT gateway, unless mirror copies it into ECR first. The domain’s hosted zone must be in the same account.

const backend = yield* Convex.Backend("Backend", {
image: "ghcr.io/convex/convex-backend:latest@sha256:<digest>",
domain: { cloud: "cloud.example.com", site: "site.example.com" },
db: { engine: "postgres", instanceClass: "db.t4g.medium", storage: 50 },
});
yield* Convex.Functions("Functions", { backend, rootDir: "." });

A server you already run

const backend = yield* Convex.Backend("Backend", {
image,
domain,
db: { engine: "mysql", url: yield* Config.Redacted("DATABASE_URL") },
});

A file on the task’s disk, for development

const backend = yield* Convex.Backend("Backend", {
image,
domain,
db: { engine: "sqlite" },
});
const backend = yield* Convex.Backend("Backend", {
image,
db,
domain: {
cloud: "cloud.example.com",
site: "site.example.com",
dns: Cloudflare.DNS.Adapter(),
},
});

One stage on a shared Convex.Platform

const { convex } = yield* Platform;
const backend = yield* Convex.Backend("Backend", { platform: convex, image });

A stage named alice gets alice.cloud.<domain> and alice.site.<domain>, or whatever the platform’s hosts template names. The production backend gets cloud.<domain> and site.<domain>, a protected database, and no SQLite. That’s the prod stage unless you say otherwise.

A production stage with another name

const { stage } = yield* Stack;
const backend = yield* Convex.Backend("Backend", {
platform: convex,
image,
production: stage === "production",
});

Hosts the stage picks itself

// The platform's certificate must cover them.
const backend = yield* Convex.Backend("Backend", {
platform: convex,
image,
hosts: { cloud: "demo-api.preview.example.com", site: "demo-site.preview.example.com" },
});
const backend = yield* Convex.Backend("Backend", {
image,
domain,
db,
deletionProtection: false,
});

backend.url resolves once the backend is running, so whatever reads it waits for the service. A site only needs the address, which backend.endpoints has from the start, so it builds while the backend comes up.

const website = yield* AWS.Website.TanStackStart("Website", {
env: { CONVEX_URL: backend.endpoints.url },
});

The backend holds an exclusive lease on its database, so there is one task and a rollout stops the old one first. Expect a short outage on each deploy. A changed instance name fails the plan, because it would point the backend at a new, empty database.

Source: packages/convex/src/aws/Platform.ts

Infrastructure stages share in one AWS account: the network, ECS cluster, load balancer with a wildcard certificate, five buckets, and a database server unless every stage runs on SQLite. Deploy it once per account, from its own stack, and pass it to each Convex.Backend.

// stacks/platform.ts, deployed once to production and once to development
const isProd = stage === "prod";
const convex = yield* Convex.Platform("Convex", {
domain: isProd ? "example.com" : "previews.example.com",
// Previews run on SQLite, so the development platform needs no database.
db: isProd ? { engine: "postgres", instanceClass: "db.t4g.medium", storage: 100 } : undefined,
});
return { convex };

A stage alice gets alice.cloud.<domain> and alice.site.<domain> unless hosts says otherwise. {stage} and {app} go in the first label, which the platform’s wildcard certificate covers, so a new stage never waits for a certificate.

Flat hosts under one wildcard

const convex = yield* Convex.Platform("Convex", {
domain: "preview.example.com",
hosts: { cloud: "{stage}-api.{domain}", site: "{stage}-site.{domain}" },
});
// stage pippo: pippo-api.preview.example.com, pippo-site.preview.example.com

Two apps on one platform

const convex = yield* Convex.Platform("Convex", {
domain: "preview.example.com",
hosts: { cloud: "{stage}-{app}-api.{domain}", site: "{stage}-{app}-site.{domain}" },
});
// in each app's stack
const backend = yield* Convex.Backend("Backend", { platform: convex, image, app: "shop" });

deletionProtection is on by default, so destroying a platform fails until you set it to false and deploy.

Source: packages/convex/src/aws/StageDatabase.ts

One stage’s database and user on a shared Convex.Platform server, and its prefix in the shared buckets. Convex.Backend creates one, so most stacks never use this directly. Destroying it drops the database and deletes the prefix, and only that prefix.

A database has no tags, so an SSM parameter beside it names the resource that owns it. A second resource for the same database is refused unless it adopts, and adopting moves ownership, so the old resource’s destroy leaves the data.

The server is in private subnets, so the SQL runs through the platform’s in-VPC function. The master password is read from SSM here, on the deploying machine, so it never lands in a stage’s state.

Source: packages/convex/src/aws/StageStorage.ts

A SQLite stage’s prefix in a Convex.Platform’s shared buckets. It creates nothing; destroying it deletes the prefix, and only that prefix. A stage on the platform’s database server gets the same cleanup from its stage database.