Cloud Deployment Options
Choose based on your needs:- Platform as a Service (PaaS) - Easiest, minimal configuration
- Container Services - Flexible, Docker-based
- Kubernetes - Maximum control, complex setup
- Serverless - Pay per request, auto-scaling
- Virtual Machines - Full control, more management
Platform as a Service (PaaS)
PaaS platforms handle infrastructure, letting you focus on code.Render
Render is a modern PaaS with excellent FastAPI support.1
Create render.yaml
2
Connect Repository
Link your GitHub/GitLab repository in Render dashboard.
3
Deploy
Render automatically deploys on every git push.
- Free tier available
- Automatic HTTPS
- Auto-deploy from git
- Built-in monitoring
Render automatically provides HTTPS certificates and handles renewals.
Railway
Railway offers simple deployment with great developer experience.1
Install Railway CLI
2
Login and Initialize
3
Deploy
- Generous free tier
- PostgreSQL/Redis included
- Environment variables management
- Automatic HTTPS
Fly.io
Fly.io runs your app in containers close to your users.1
Install Flyctl
2
Launch App
fly.toml configuration.3
Deploy
- Global edge deployment
- Automatic HTTPS
- Scale to zero
- Pay-as-you-go pricing
Heroku
Heroku is a mature PaaS with extensive documentation.1
Create Procfile
2
Create runtime.txt
3
Deploy
- Add-ons marketplace (databases, monitoring, etc.)
- Automatic HTTPS
- Easy scaling
- CI/CD integration
Heroku removed its free tier in 2022. Consider Render or Railway for free hosting.
Container Services
Deploy Docker containers without managing orchestration.AWS App Runner
App Runner automatically builds and deploys containerized applications.1
Create Dockerfile
2
Deploy via AWS Console
- Open App Runner console
- Create service from source code or ECR
- Configure port (8000)
- Deploy
- Automatic scaling
- Built-in load balancing
- HTTPS included
- Pay for what you use
Google Cloud Run
Cloud Run runs containers in a fully managed environment.1
Create Dockerfile
2
Build and Deploy
- Scale to zero (no cost when idle)
- Automatic HTTPS
- Pay per request
- Fast cold starts
Cloud Run automatically injects
$PORT environment variable. Use it in your start command.Azure Container Instances
ACI quickly deploys containers without managing servers.- Simple container deployment
- Per-second billing
- Fast startup
- Virtual network support
Kubernetes Platforms
Managed Kubernetes for production-grade deployments.AWS EKS
Elastic Kubernetes Service runs Kubernetes on AWS. deployment.yaml:Google Kubernetes Engine (GKE)
GKE offers managed Kubernetes with Autopilot mode.- Autopilot mode (fully managed)
- Auto-scaling
- Auto-repair
- Integrated monitoring
Azure Kubernetes Service (AKS)
AKS provides managed Kubernetes on Azure.Serverless Platforms
Run FastAPI without managing servers, paying only for actual usage.AWS Lambda with Mangum
Mangum is an adapter for running ASGI apps on AWS Lambda. Installation:Lambda has a cold start delay. Consider provisioned concurrency for latency-sensitive applications.
Vercel
Vercel supports Python serverless functions. api/index.py:- 10 second timeout on hobby tier
- Limited CPU/memory
- Best for simple APIs
Virtual Machines
Full control with self-managed infrastructure.DigitalOcean Droplet
1
Create Droplet
Create Ubuntu 22.04 droplet via DigitalOcean console.
2
SSH and Setup
3
Deploy Application
4
Setup Systemd Service
Create Enable and start:
/etc/systemd/system/fastapi.service:5
Configure Nginx
Create Enable:
/etc/nginx/sites-available/fastapi:6
Setup HTTPS
Database Integration
Most cloud platforms offer managed database services.PostgreSQL Options
- AWS: RDS, Aurora
- Google Cloud: Cloud SQL
- Azure: Azure Database for PostgreSQL
- Neon: Serverless Postgres
- Supabase: Open-source Firebase alternative
- PlanetScale: MySQL-compatible
Example Connection
Use connection pooling and environment variables for database credentials. Never hardcode credentials.
Environment Variables
Manage configuration across environments.Using python-dotenv
Platform-Specific
Render:Monitoring and Logging
Application Performance Monitoring
Sentry for error tracking:Structured Logging
Cloud Platform Monitoring
- AWS: CloudWatch
- Google Cloud: Cloud Logging, Cloud Monitoring
- Azure: Application Insights
- Render: Built-in metrics
- Railway: Built-in logs
Recap
Choosing a cloud platform:1
Start Simple
PaaS (Render, Railway, Fly.io) for quick deployment with minimal configuration.
2
Scale with Containers
Container Services (Cloud Run, App Runner) when you need more control but managed infrastructure.
3
Advanced Needs
Kubernetes (EKS, GKE, AKS) for complex applications requiring advanced orchestration.
4
Serverless for Spikes
Lambda/Serverless for infrequent usage or extreme cost optimization.
- ✅ Cost: PaaS vs. IaaS pricing models
- ✅ Scaling: Auto-scaling capabilities
- ✅ HTTPS: Automatic certificate management
- ✅ Databases: Managed vs. self-hosted
- ✅ Monitoring: Built-in vs. third-party
- ✅ Complexity: Learning curve and maintenance