Defang Blog

FastAPI deployment Heroku vs AWS / GCP with Defang

3 min read
Fast API, Heroku, Defang Logos

Defang brings Heroku’s simplicity to your own cloud: deploy FastAPI apps to AWS or GCP with a single command using your existing Docker Compose. You keep full ownership, pay raw cloud costs, and stay portable. No platform lock-in, same Heroku-style workflow.

FastAPI is getting more and more popular, as is building agents. Developers building agentic systems are starting to turn to FastAPI as one of the more ergonomic web frameworks for building endpoints and then adding on a Model Context Protocol (MCP) layer so that AI agents can discover and invoke those endpoints as “tools”. For example, with FastAPI-MCP you can take an existing FastAPI application, attach mcp = FastApiMCP(app) and mcp.mount(), and your endpoints become usable by an LLM-based agent with minimal extra work.

But when it comes time to deploy your agent, how should you go about it?

TL;DR: Heroku is great to start, but you pay for convenience with higher tiers, less control, and platform lock‑in. Defang keeps the Heroku‑like workflow but deploys your FastAPI app into your own AWS or GCP account—you keep ownership, pay for cloud resources plus a Defang subscription, and ship with a single command.

What “shipping FastAPI” looks like on Heroku

A common Heroku setup runs FastAPI with Gunicorn and Uvicorn workers via a Procfile, plus requirements.txt. A typical entry is:

web: gunicorn -k uvicorn.workers.UvicornWorker main:app

This pattern is popular because it uses Uvicorn as an ASGI worker under Gunicorn. It’s easy to get running, but your region choices and infrastructure are limited by the Heroku platform.

What “shipping FastAPI” looks like on AWS/GCP with Defang

Defang reads your Docker Compose file to describe the app, then deploys it to your own AWS or GCP account with one command. You define your services once and deploy them the same way each time, but you own the account and have direct control over networking and managed services.

Try it locally with:

docker compose up

Then deploy to your cloud:

defang --provider=aws compose up

or

defang --provider=gcp compose up

Defang transforms Compose files into cloud resources (compute, networking, TLS, storage) and wires managed Postgres/Redis when needed.

Why choose AWS/GCP + Defang over Heroku for FastAPI

Ownership & control

Heroku abstracts infrastructure. Defang deploys into your cloud account. You choose regions, networking, and compliance boundaries. Heroku does allow a region choice at app creation, but options are much more limited.

Cost basis

With Defang you pay for AWS/GCP resources plus a Defang subscription (e.g., $10–$30/user/month). You avoid Heroku’s dyno pricing. For comparison, a Standard‑1X dyno on Heroku costs $25/month, and Performance‑M costs $250/month. Data services are add‑ons (an Essential‑0 Postgres instance is ~$5/month). Heroku’s pricing is easy to understand but can be expensive at larger scales. Defang uses your cloud provider’s pay‑as‑you‑go model and supports cost‑saving deployment modes.

Portability and lock‑in

Heroku workflows can bind you to dynos and their add‑on ecosystem, making migration more involved. Defang uses standard containers and cloud services, so your Compose definition is portable across supported providers. Leaving Defang still requires replacing the automation we provide, but the configuration remains in Compose and everything is built with standard primitives from your chosen cloud.

Developer experience

Heroku’s appeal is its deploy experience: commit, push, and it’s live. Defang preserves that simplicity with a Compose‑driven workflow and a one‑command deploy. Updating your app triggers a diff and apply, rather than a fresh manual setup each time.

Head‑to‑head considerations

  • Where it runs:
    Heroku deploys your app on its own platform in a region you choose at creation.
    Defang deploys it in your AWS or GCP account, so you control networks, VPCs, policies, etc.
  • Deploy flow:
    Heroku uses a Procfile and recommends servers like Gunicorn or Uvicorn.
    Defang uses your Compose file and runs defang compose up to provision services.
  • Databases & caching:
    Heroku allows you to attach add‑ons for Postgres or Redis.
    Defang provisions managed Postgres (AWS RDS or GCP Cloud SQL) and Redis (Elasticache or Memorystore) directly in your account.
  • Costs at scale:
    Heroku pricing is tiered by dyno size; high performance dynos can reach $250–$1,500/month.
    Defang charges a subscription and then you pay AWS/GCP usage, which is often lower than Heroku, especially with Spot or smaller instances.
  • Lock‑in:
    Heroku’s dynos and add‑ons tie you to its platform.
    Defang uses open formats and cloud primitives, making migration easier if you decide to run infrastructure yourself later.

Migrating a FastAPI app: Heroku → AWS/GCP

Defang’s migration flow inspects your Heroku app, generates a Compose file, provisions equivalents like Postgres/Redis on your cloud, then deploys with one command. In practice, this means:

  1. Analyze dynos, environment variables and add‑ons on your Heroku app.
  2. Generate a Compose definition that mirrors your services.
  3. Build & Deploy the app on AWS or GCP with a single defang compose up.

No code rewrite is required.

Minimal snippets

Heroku (Procfile)

web: gunicorn -k uvicorn.workers.UvicornWorker main:app

Heroku Dev Center recommends using a production server such as Gunicorn or Uvicorn. FastAPI typically runs with Uvicorn workers.

Defang (Compose File + CLI Commands)

Defang reads your Compose file and deploys, provisioning compute, networking and managed databases.

When to pick which

  • Heroku is ideal for quick prototypes or side projects where you accept platform limits and want an easy dyno-based deployment that you do not expect to scale much.
  • AWS/GCP + Defang makes sense once costs, control and ownership matter: especially for production FastAPI apps that need specific regions, VPC configurations or compliance requirements.

Try it yourself

You can see Defang in action with a one‑click FastAPI deployment. In a few minutes you’ll have FastAPI running in your own AWS or GCP account using the Heroku‑style workflow, no custom infra scripts required.

👉 Deploy FastAPI on Defang in one click

FAQ

Is Defang more complex than Heroku? No. Defang is designed to feel like Heroku: simple CLI deploys, but under the hood it translates a Compose file into cloud resources. You get a similar workflow with more control. Currently we generate one for you, but we're also working on completely removing the Compose file requirement where possible.

Can I migrate an existing Heroku FastAPI app without rewriting it? Yes. Defang analyzes your dynos, add‑ons and env vars, generates a Compose file, and provisions the equivalent services automatically.

What about databases like Postgres or caching with Redis? On Heroku these are add‑ons. With Defang they are provisioned directly in your AWS/GCP account, using RDS/Cloud SQL for Postgres and Elasticache/Memorystore for Redis, so your data stays in your environment.

How does pricing compare? Heroku charges a monthly or hourly fee per dyno and add‑on (e.g., $25/month for a Standard‑1X dyno). Defang charges a small subscription fee, and you pay the underlying cloud costs directly to your cloud provider.

Why not just write Terraform or Kubernetes myself? You can, but that takes time and expertise. Defang provides a “define once → deploy anywhere” workflow; you can extend infrastructure later if you need more customization.

Related posts

Defang Compose Up(date)
5 min read

September 2025 Defang Compose Update

September focused on refinement and speed. We tightened deployment workflows, strengthened authentication, and made collaboration smoother across every environment. We improved Portal stability, added Railpack build logs, and refined Compose handling for managed services like Postgres, Mongo, and Redis. WAF is now enabled for high availability on AWS, and our VS Code extension is verified on the Marketplace with an easier MCP setup built right into the installer. Here’s what’s new.

← Back to all posts