Build a Serverless API using AWS Lambda, CDK, and Neon
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.
Related posts
- 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.
- Deploy a Serverless FastAPI App with Neon Postgres and AWS App Runner at any scale
Neon mediumAdept
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.
- Build a Dynamic E-Commerce Store UI with Astro, Neon Postgres, and AWS Amplify
Neon mediumAdept
An e-commerce storefront built with Astro in server-rendered mode, reading products from Neon serverless Postgres over HTTP through the @neondatabase/serverless driver and deployed to AWS Amplify on every Git commit. The walkthrough covers provisioning a pooled Neon connection string, adding Tailwind, configuring the astro-aws-amplify adapter and an amplify.yml that copies node_modules and .env into the compute bundle, and seeding a products table with a tsx script. It then builds a shared layout, a product listing page, and a dynamic /p/[slug] product page.
- Simplify Serverless in AWS: How to Use Neon and Ephemeral Environments
Neon mediumAdept
Neon's serverless Postgres pairs well with ephemeral environments on AWS Lambda because each environment can get its own instant copy-on-write database branch without paying for extra RDS uptime. Compared with Aurora Serverless v2, Neon claims ~500ms cold starts versus 15s, built-in PgBouncer supporting 10,000 connections, and an HTTP/WebSocket data API. A TODO API built with the Serverless Framework shows how the serverless driver's sql template tag guards against SQL injection, but only when called directly on a string literal, and how sql.query with $n placeholders handles dynamic updates. Scripts and GitHub Actions create a branch per feature or CI run, run unit and end-to-end tests against it, then tear down both the stack and the branch.
- 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.