Skip to content

Convex.Deployment reference

Source: packages/convex/src/CanonicalUrl.ts

The canonical URL of a Convex deployment, usually a custom domain. Removing this resource restores the default.

yield* Convex.CanonicalUrl("Site", {
deployment,
requestDestination: "convexSite",
url: "https://site.example.com",
});

Source: packages/convex/src/CustomDomain.ts

A custom domain on a Convex deployment.

yield* Convex.CustomDomain("Api", {
deployment,
domain: "api.example.com",
requestDestination: "convexCloud",
});

Source: packages/convex/src/DataSync.ts

Export a Convex deployment’s data from a Worker, Lambda or other host, a page at a time.

The host gets a deploy key that can only do deployment:data:view on this deployment, which reads every table. The Deployment API accepts only Convex’s own keys, so there is no host identity to federate.

Effect.gen(function* () {
const data = yield* Convex.DataSync(Backend);
return {
fetch: Effect.gen(function* () {
const page = yield* data.sync({});
return yield* HttpServerResponse.json(page);
}),
};
}).pipe(Effect.provide(Convex.DataSyncHttp));

Source: packages/convex/src/Deployment.ts

A Convex deployment: one database and set of functions in a project.

Prod deployments have deletionProtection on, so alchemy destroy fails rather than deleting their data.

Changing project transfers the deployment, so it keeps its data, name and URL. Changing region replaces it.

Previews expire on Convex’s side. The next deploy notices and creates a new one, which has a new name and URL and no data.

Default production deployment

const prod = yield* Convex.Deployment("Prod", { project, type: "prod" });

One preview per stage, removed by alchemy destroy

const preview = yield* Convex.Deployment("Preview", { project, type: "preview" });

A dev deployment with its own reference

const dev = yield* Convex.Deployment("Dev", {
project,
type: "dev",
reference: "dev/sam",
});

Changing region replaces the deployment and starts it with no data.

const eu = yield* Convex.Deployment("Eu", {
project,
type: "prod",
region: "aws-eu-west-1",
});
const deployment = yield* Convex.Deployment("Backend", {
project: newProject,
type: "dev",
});

A paused deployment keeps its data, and function calls fail until it resumes. Scheduled jobs queue, and crons are skipped.

const deployment = yield* Convex.Deployment("Backend", {
project,
type: "prod",
paused: true,
});
const prod = yield* Convex.Deployment("Prod", {
project,
type: "prod",
deletionProtection: false,
});

Deployment: Calling Functions from a Runtime

Section titled “Deployment: Calling Functions from a Runtime”
Effect.gen(function* () {
const list = yield* Convex.RunQuery(Backend);
return {
fetch: Effect.gen(function* () {
return yield* HttpServerResponse.json(yield* list("messages:list"));
}),
};
}).pipe(Effect.provide(Convex.RunQueryHttp));

Source: packages/convex/src/GetCurrentUsage.ts

Read a Convex deployment’s current usage from a Worker, Lambda or other host.

The host gets a deploy key that can only do deployment:usage:view on this deployment. Convex marks this API as beta. The Deployment API accepts only Convex’s own keys, so there is no host identity to federate.

Effect.gen(function* () {
const usage = yield* Convex.GetCurrentUsage(Backend);
return {
fetch: Effect.gen(function* () {
const { metrics } = yield* usage();
return yield* HttpServerResponse.json(metrics.functionCalls);
}),
};
}).pipe(Effect.provide(Convex.GetCurrentUsageHttp));

Source: packages/convex/src/ListAuditLogEvents.ts

Read a Convex deployment’s audit log from a Worker, Lambda or other host.

The host gets a deploy key that can only do deployment:auditLog:view on this deployment. The Deployment API accepts only Convex’s own keys, so there is no host identity to federate.

Effect.gen(function* () {
const audit = yield* Convex.ListAuditLogEvents(Backend);
return {
fetch: Effect.gen(function* () {
const page = yield* audit({ from: Date.now() - 3_600_000 });
return yield* HttpServerResponse.json(page.items);
}),
};
}).pipe(Effect.provide(Convex.ListAuditLogEventsHttp));

Source: packages/convex/src/UsageLimit.ts

A usage limit on a Convex deployment. A disable limit pauses the deployment when it is reached.

Convex allows one limit per metric, window and type on a deployment.

yield* Convex.UsageLimit("Calls", {
deployment,
metric: "functionCalls",
window: "month",
limitType: "warning",
limit: 1_000_000,
});