Deploy a Serverless FastAPI App with Neon Postgres and AWS App Runner at any scale
A step-by-step setup for a Python API built with FastAPI and SQLModel, backed by Neon serverless Postgres and deployed to AWS App Runner with automatic deploys on each Git push. The database connection string is stored as a SecureString in AWS SSM Parameter Store and injected through apprunner.yaml secrets, with access granted by an IAM instance role. Practical details include using psycopg 3 by rewriting the URL scheme to postgresql+psycopg, and setting SQLAlchemy pool_recycle=300 to match Neon's 5-minute compute auto-suspend. pool_pre_ping is offered as an alternative that adds connection latency.
Related posts
- Fullstack Serverless CI/CD in AWS Amplify Hosting with Postgres Database Branching
Neon mediumAdept
Each AWS Amplify Hosting app branch can get its own isolated Neon Postgres database branch, created automatically during CI/CD by a custom neon-ci.sh script that calls the Neon CLI and writes the branch connection string into DATABASE_URL in a .env file. The setup uses an amplify.yml build spec, an SSM SecureString for the Neon API key, IAM policy additions on the Amplify service role, and branch auto-detection. An optional cleanup-branches command deletes Neon branches that no longer have a matching Amplify branch. A Nuxt SSR server route then queries the branch database with the Neon serverless driver, and migrations with Drizzle or Prisma can run in the same pipeline.
- Build a Serverless API using AWS Lambda, CDK, and Neon
Neon mediumAdept
A step-by-step build of a single-endpoint REST API on AWS Lambda, defined with AWS CDK v2 in TypeScript, that returns a product list from a Neon serverless Postgres database. The Lambda uses the Neon serverless driver (HTTP/WebSockets instead of TCP) and fetches the connection string from AWS Secrets Manager once via top-level await, so it isn't retrieved on every request. The CDK stack bundles the function as ESM for Node 20, grants a secretsmanager:GetSecretValue policy and wires it to an API Gateway RestApi GET /products route. Open CORS is used for the demo, with a note to restrict origins in production.
- Build a serverless API using Cloudflare Workers, Drizzle ORM, and Neon
Neon mediumAdept
A step-by-step setup for a serverless TypeScript API on Cloudflare Workers that uses Hono for routing, Drizzle ORM for schema definition and migrations, and Neon serverless Postgres for storage. It scaffolds a Worker with create-cloudflare, defines a products table in TypeScript, and uses drizzle-kit to generate SQL migrations. Migrations run through a postgres.js script capped at a single connection so they execute in order. The Worker queries Neon over HTTP via @neondatabase/serverless, is deployed with wrangler, and gets its DATABASE_URL from Cloudflare's Neon integration instead of manually configured secrets.
- Web-based AI SQL Playground and connecting to Postgres from the browser
Neon mediumAdept
Neon's Postgres AI Playground connects to a Postgres database directly from the browser and uses OpenAI's gpt-3.5-turbo to turn natural-language prompts into SQL. Browsers can't open TCP connections, so the Neon serverless driver tunnels the Postgres wire protocol through a WebSocket-to-TCP proxy. The proxy is open source and can be self-hosted to reach other Postgres providers. A Vercel edge function rate-limits requests with Upstash Redis, injects the user's schema (pulled from information_schema.columns and flattened to a compact text form) into the prompt, and streams the model's response back to the editor.
- database.build v2: Bring-your-own-LLM
Supabase mediumAdeptdatabase.build, Supabase's in-browser Postgres sandbox built on PGlite, now lets users bring any OpenAI-compatible LLM, with no login and no rate limits. Requests go straight from the browser to the provider. This works because most LLM APIs send CORS headers, and a service worker intercepts the Vercel AI SDK's /api/chat route, reading its BYO-LLM config from IndexedDB. Models need reliable tool calling, SQL knowledge and Chart.js knowledge, so gpt-4o is recommended; local Ollama models still struggle with tool calls, and Ollama buffers tool-call streams. The release also adds one-click deploys to Supabase by piping server-side pg_dump over Live Share into pg_restore, and replaces the tar.gz export with a WASM pg_dump. Serverless PGlite was shelved because of its memory use and single-connection limit in multi-tenant setups and unreliable s3fs storage.