---
title: "Deploy a Serverless FastAPI App with Neon Postgres and AWS App Runner at any scale"
description: "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."
url: "https://swe.quest/articles/deploy-a-serverless-fastapi-app-with-neon-postgres-and-aws-app-runner-at-any-6068dfbf055e1e25"
canonical: "https://neon.com/blog/deploy-a-serverless-fastapi-app-with-neon-postgres-and-aws-app-runner-at-any-scale"
source: "Neon"
published: "2024-02-09"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["python","postgres","serverless","cloud","deployment"]
---

# Deploy a Serverless FastAPI App with Neon Postgres and AWS App Runner at any scale

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-02-09, 11 min read, How-to. Original: [https://neon.com/blog/deploy-a-serverless-fastapi-app-with-neon-postgres-and-aws-app-runner-at-any-scale](https://neon.com/blog/deploy-a-serverless-fastapi-app-with-neon-postgres-and-aws-app-runner-at-any-scale)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Python](https://swe.quest/tags/python.md) (Languages)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)
- [Deployment](https://swe.quest/tags/deployment.md) (Reliability & operations)

## Prerequisites

- Python web APIs ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- AWS IAM basics ([easy posts on Cloud platforms](https://swe.quest/tags/cloud.md?difficulty=easy))
- PostgreSQL connection strings ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

FastAPI, Neon, AWS App Runner, AWS Systems Manager Parameter Store, SQLModel, psycopg, Poetry, uvicorn

## Related posts

- [Fullstack Serverless CI/CD in AWS Amplify Hosting with Postgres Database Branching](https://swe.quest/articles/fullstack-serverless-ci-cd-in-aws-amplify-hosting-with-postgres-database-5ab5e970ace5ba81.md): Neon · 2024-03-06 · Medium · 10 min read · CI/CD, PostgreSQL, Serverless, Cloud platforms, Deployment
  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.
- [Build a Serverless API using AWS Lambda, CDK, and Neon](https://swe.quest/articles/build-a-serverless-api-using-aws-lambda-cdk-and-neon-939349a37c380ca9.md): Neon · 2023-11-30 · Medium · 11 min read · Serverless, Infrastructure as code, PostgreSQL, Cloud platforms, TypeScript
  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.
- [Build a serverless API using Cloudflare Workers, Drizzle ORM, and Neon](https://swe.quest/articles/build-a-serverless-api-using-cloudflare-workers-drizzle-orm-and-neon-f83c472c9d399a17.md): Neon · 2023-05-30 · Medium · 9 min read · Serverless, PostgreSQL, TypeScript, Schema migrations
  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.
- [Web-based AI SQL Playground and connecting to Postgres from the browser](https://swe.quest/articles/web-based-ai-sql-playground-and-connecting-to-postgres-from-the-browser-fa7f4eccd9643a37.md): Neon · 2023-05-19 · Medium · 5 min read · PostgreSQL, LLMs, Serverless, JavaScript
  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.
- [database.build v2: Bring-your-own-LLM](https://swe.quest/articles/database-build-v2-bring-your-own-llm-b2a3b83eee7ef5a0.md): Supabase · 2024-12-06 · Medium · 11 min read · PostgreSQL, LLMs, Browsers, WebAssembly
  database.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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
