{"catalogRevision":"cat_f13ab9a494120b5e","recipeId":"page:recipes:rest-api:fastify:persistent-state","recipeRevision":"r1","canonicalPath":"/recipes/rest-api/fastify/persistent-state","label":"Host rest api with Fastify: Postgres-backed state","family":"Workload recipe","summary":"Deploy a Fastify REST API whose durable state lives in a managed PostgreSQL 16 database. With no DATABASE_URL supplied, Ample provisions the database and injects the connection string as an encrypted environment variable; the API stores rows with pg and serves them from a public HTTPS URL.","representativeQueries":["Host rest api with Fastify: Postgres-backed state","Where can I host REST API built with Fastify?","I need a durable state schema and retry/recovery semantics implemented by application code."],"breadcrumbIds":["discovery","workload","workload:agents-and-backends","workload:rest-api","page:recipes:rest-api:fastify:persistent-state"],"breadcrumbs":[{"id":"discovery","label":"Agent hosting discovery","canonicalPath":"/discover/discovery","kind":"root"},{"id":"workload","label":"Applications and workloads","canonicalPath":"/discover/workload","kind":"facet"},{"id":"workload:agents-and-backends","label":"Agents and backends","canonicalPath":"/discover/workload/agents-and-backends","kind":"group"},{"id":"workload:rest-api","label":"REST API","canonicalPath":"/discover/workload/rest-api","kind":"atom"},{"id":"page:recipes:rest-api:fastify:persistent-state","label":"Host rest api with Fastify: Postgres-backed state","canonicalPath":"/recipes/rest-api/fastify/persistent-state","kind":"recipe"}],"parentIds":["workload:rest-api","stack:framework-fastify","pattern:durable-job-state","intent:deploy-api"],"parents":[{"id":"workload:rest-api","label":"REST API","canonicalPath":"/discover/workload/rest-api","kind":"atom"},{"id":"stack:framework-fastify","label":"Fastify","canonicalPath":"/discover/stack/framework-fastify","kind":"atom"},{"id":"pattern:durable-job-state","label":"Durable job state","canonicalPath":"/discover/pattern/durable-job-state","kind":"atom"},{"id":"intent:deploy-api","label":"Deploy API","canonicalPath":"/discover/intent/deploy-api","kind":"atom"}],"resourceRequirements":["primitive:compute","primitive:postgres"],"infrastructureRequirements":[{"primitiveId":"primitive:compute","label":"Compute","canonicalPath":"/discover/primitive/compute","status":"verified","summary":"Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes."},{"primitiveId":"primitive:postgres","label":"Postgres","canonicalPath":"/discover/primitive/postgres","status":"verified","summary":"Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied."}],"framework":"Fastify","workload":"REST API","releaseStatus":"published","supportStatus":"verified","executionStatus":"ready","docsOnly":false,"prerequisites":["A package.json with a start script that listens on process.env.PORT and 0.0.0.0","The pg driver reading process.env.DATABASE_URL","Tables created by the app or by a --release-command migration, not assumed to exist","An Ample account token with servers:write and databases:read"],"testedConfiguration":{"template":"node-22","runtime":"node","size":"s-1vcpu-1gb","install":"npm install","build":"npm run build --if-present","start":"npm run start"},"inputSchema":{"additionalProperties":false,"properties":{"env":{"description":"Encrypted environment variables as KEY=value; secret values are never stored in ample.toml","items":{"pattern":"^[A-Z][A-Z0-9_]*=.*$","type":"string"},"maxItems":50,"type":"array"},"name":{"description":"App name (lowercase, digits and dashes)","maxLength":63,"minLength":1,"pattern":"^[a-z0-9-]+$","type":"string"},"path":{"description":"Project directory to deploy, or one service name from ample.toml","maxLength":512,"minLength":1,"type":"string"},"release_command":{"description":"One-off command run before the release goes live, for example a migration","maxLength":512,"minLength":1,"type":"string"},"size":{"description":"VM size; omit to let Ample pick a runtime-safe size","enum":["s-1vcpu-256mb","s-1vcpu-1gb","s-1vcpu-2gb","s-2vcpu-2gb","s-2vcpu-4gb"],"type":"string"},"start":{"description":"Start command override when detection cannot infer it (Python apps pass one explicitly)","maxLength":512,"type":"string"}},"required":["name","path"],"type":"object"},"outputSchema":null,"workflowSteps":[{"title":"Read DATABASE_URL at runtime","body":"Open the connection from the environment inside request handlers or a pool; a local .env is replaced by the managed database in production."},{"title":"Deploy","body":"Run the existing synchronous deploy once from the project directory and read the result. Exit 0 is live, 1 is failed, 2 is blocked on a required preflight action. Re-running with no change is a content-addressed no-op.","command":"ample deploy . --name <app-name> --public --format json"},{"title":"Verify","body":"Fetch the live URL and run the success checks below. On failure read the build log, then the runtime log, fix the cause and deploy again; do not blind-retry.","command":"ample logs <deployment_id> --kind build"}],"examples":[{"title":"Fastify + PostgreSQL canary","description":"REST API with an items table in an auto-provisioned managed PostgreSQL database.","sourceRef":"tests/deploy-canaries/fastify-postgres-api"}],"successChecks":[{"description":"root route responds","kind":"http_get","path":"/","expect":"ample canary fastify postgres api"},{"description":"database insert and count succeed","kind":"http_get","path":"/items","expect":"postgres=ok"}],"limitations":["Verified on the node-22 template at s-1vcpu-1gb; other templates and sizes are not verified by this recipe.","Region, compliance attestations and request-duration limits are unknown and not claimed.","Apps auto-pause when idle and wake on the next request; always-on is an operator setting, not a plan feature.","Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.","Apps and their managed databases are placed together; cross-node shared databases are unsupported."],"costEstimate":{"currency":"USD","monthlyAmount":10.0,"authoritative":true,"basis":"size prices from pricing.toml (loaded by the API) at build revision 7cf090725a6f16dd91af7d28356fe72c1b404d6e","components":[{"name":"app server","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0},{"name":"managed PostgreSQL database","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0}],"note":"Apps and managed databases auto-pause when idle; the estimate is the always-on monthly price of the tested sizes. Plan quotas and budgets apply."},"evidenceSummary":[{"kind":"canary_run","summary":"Fastify REST API using pg with no DATABASE_URL supplied: Ample auto-provisioned a managed PostgreSQL 16 database and /items reported postgres=ok after a real insert and count.","observedAt":"2026-09-20T01:42:25Z","implementationRevision":"199ff1dfd52683832ae75d3f98b53a7a4bff7f96 (CLI e3181f5)","expiresAt":"2027-03-19T01:42:25Z","scope":{"cliVersion":"0.1.20","platform":"hosted","template":"node-22"}},{"kind":"canary_run","summary":"Node app needing PostgreSQL with no DATABASE_URL: a managed database was auto-provisioned and /db reported postgres=ok.","observedAt":"2026-09-19T23:55:33Z","implementationRevision":"1764076-tls-account-903d345","expiresAt":"2027-03-18T23:55:33Z","scope":{"cliVersion":"0.1.20","platform":"hosted","template":"node-22"}}],"lastVerifiedAt":"2026-09-20T01:42:25Z","mcpBinding":{"registryRef":"mcp:ample_deploy","toolName":"ample_deploy","schemaHash":"876465fce906da0c224d62961d3343064108ebe30af80cf1b87094974e948853","observedAt":"2026-09-20T01:55:48.667900+00:00","implementationRevision":"199ff1dfd526","requiredScopes":["servers:write","databases:read"],"bindingState":"current"},"unknowns":["region availability is unknown until a verified region fact is recorded","compliance attestations are unknown; none are claimed"],"formats":{"html":"https://ample.computer/recipes/rest-api/fastify/persistent-state","markdown":"https://ample.computer/recipes/rest-api/fastify/persistent-state.md","json":"https://api.ample.computer/v1/catalog/recipes/page%3Arecipes%3Arest-api%3Afastify%3Apersistent-state"},"nextActions":[{"actionId":"browse-catalog","label":"Browse the catalog index","operationId":"catalog_index","method":"GET","relativePath":"/v1/catalog","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"search-recipes","label":"Search published recipes by intent, stack and constraints","operationId":"search_recipes","method":"POST","relativePath":"/v1/catalog/search","origin":"api","parameters":{"body":{"limit":5,"query":"Host rest api with Fastify: Postgres-backed state"}},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"plan:page:recipes:rest-api:fastify:persistent-state","label":"Prepare a side-effect-free deployment plan for an authorized project","operationId":"plan_deployment","method":"POST","relativePath":"/v1/catalog/plan","origin":"api","parameters":{"body":{"inputs":{},"projectId":"<workspace or server id you own>","recipeId":"page:recipes:rest-api:fastify:persistent-state","recipeRevision":"r1"}},"requiresAuthentication":true,"requiresApproval":false},{"actionId":"auth-setup","label":"Read the existing agent authentication setup","operationId":"existing_auth_setup","method":"GET","relativePath":"/mcp/setup","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:workload:rest-api","label":"Browse REST API","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/workload%3Arest-api","origin":"api","parameters":{"nodeId":"workload:rest-api"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:stack:framework-fastify","label":"Browse Fastify","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/stack%3Aframework-fastify","origin":"api","parameters":{"nodeId":"stack:framework-fastify"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:pattern:durable-job-state","label":"Browse Durable job state","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/pattern%3Adurable-job-state","origin":"api","parameters":{"nodeId":"pattern:durable-job-state"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:intent:deploy-api","label":"Browse Deploy API","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/intent%3Adeploy-api","origin":"api","parameters":{"nodeId":"intent:deploy-api"},"requiresAuthentication":false,"requiresApproval":false}]}