USD ($)
$
United States Dollar
Euro Member Countries
India Rupee

Deployment to Cloud Platforms

Lesson 20/30 | Study Time: 23 Min

Deployment to cloud platforms such as Heroku, AWS Lambda, and Railway enables applications to be hosted, scaled, and managed without maintaining physical infrastructure.

These platforms provide tools and services that simplify application deployment, environment configuration, and scaling. Each platform supports different deployment models, ranging from fully managed application hosting to serverless execution, allowing developers to choose solutions based on application requirements and workload patterns.

Platform Overview

Cloud platforms simplify API deployment by handling infrastructure, but each suits different needs in web API workflows.

Heroku offers a PaaS model with Git-based deploys, ideal for quick starts on traditional web servers. AWS Lambda provides serverless execution, charging only for requests and compute time, perfect for event-driven APIs. Railway combines ease with modern features like visual project views and lower costs, bridging Heroku's simplicity and advanced scaling

Comparison 

Deploy to Heroku

Heroku excels for beginner-friendly deploys of FastAPI or Flask apps using its Python buildpack.

Start with a verified account and Heroku CLI installed. Ensure your project has a requirements.txt (generate via pip freeze > requirements.txt) and a Procfile like web: gunicorn main:app—where main:app points to your FastAPI instance.

​1. Initialize Git: git init, git add ., git commit -m "Initial commit".

2. Create app: heroku create your-app-name.

3. Add remote: heroku git:remote -a your-app-name.

4. Deploy: git push heroku main.

5. Scale: heroku ps:scale web=1.

6. Open: heroku open—test endpoints like /docs for FastAPI Swagger UI.

Example Procfile for FastAPI

text
web: gunicorn main:app --bind 0.0.0.0:$PORT -w 4


Use .python-version (e.g., 3.12) for runtime control. Logs via heroku logs --tail help debug. Best practice: Set config vars (heroku config:set KEY=VALUE) for secrets like database URLs.

Deploy to AWS Lambda

AWS Lambda suits serverless Web APIs, invoking code on HTTP requests via API Gateway for zero idle costs.

Prepare a lambda_handler adapting FastAPI with Mangum (ASGI adapter). Install deps: pip install fastapi uvicorn mangum -t dependencies/, zip them with main.py.

​main.py Example

python
from fastapi import FastAPI
from mangum import Mangum

app = FastAPI()
@app.get("/")
def read_root(): return {"Hello": "Lambda"}

handler = Mangum(app)


1. Create Lambda function in console (Python 3.12 runtime).

2. Upload ZIP (code + deps).

3. Set handler: main.handler.

4. Add API Gateway trigger: HTTP API, proxy integration /{proxy+}.

​5. Deploy—get invoke URL.

For larger apps, use container images via ECR to bypass 250MB limits. Environment vars via console; monitor with CloudWatch. Cold starts (initial latency) improve with Provisioned Concurrency for production.

Deploy to Railway

Railway streamlines deploys with Git integration and no-dyno-sleep, great for full-stack APIs.

Sign up, install CLI: npm i -g railway. Project needs requirements.txt; optional Dockerfile for custom builds (e.g., FROM python:3.12, CMD ["uvicorn", "main:app"]).

1. railway login

2. railway init (link GitHub repo).

3. railway up—auto-detects Python, builds, deploys.

4. Set vars: railway variables set KEY=VALUE.

5. Generate domain or custom DNS.

Access via provided URL; auto-deploys on Git pushes. Visual dashboard shows metrics/logs; supports databases as linked services. For FastAPI, hit /docs post-deploy.

Best Practices

Follow these to ensure robust, secure deployments across platforms.



himanshu singh

himanshu singh

Product Designer
Profile

Class Sessions

1- HTTP Methods and REST Principles 2- Status Codes, Headers, and Request/Response cycles 3- JSON and XML Data Formats for API Payloads 4- Resource Naming Conventions and URI Design Best Practices 5- Statelessness, HATEOAS, and API Versioning Strategies 6- Rate Limiting, Caching, and Idempotency for Scalability 7- FastAPI Setup, Pydantic Models, and Async Endpoint Creation 8- Path/Query Parameters, Request/Response Validation 9- Dependency Injection and Middleware for Authentication/Authorization 10- SQLAlchemy ORM with Async Support for PostgreSQL/MySQL 11- CRUD Operations via API Endpoints with Relationships 12- Database Migrations Using Alembic and Connection Pooling 13- JWT/OAuth2 Implementation with FastAPI Security Utilities 14- File Uploads, Pagination, and Real-Time WebSockets 15- Input Sanitization, CORS, and OWASP Top 10 Defenses 16- Unit/integration testing with Pytest and FastAPI TestClient 17- API Documentation Generation with OpenAPI/Swagger 18- Mocking External Services and Load Testing with Locust 19- Containerization with Docker and Orchestration via Docker Compose 20- Deployment to Cloud Platforms 21- CI/CD Pipelines Using GitHub Actions and Monitoring with Prometheus 22- Consuming APIs in React/Vue.js with Axios/Fetch 23- State Management (Redux/Zustand) for API Data Flows 24- Error Handling, Optimistic Updates, and Frontend Caching Strategies 25- Async Processing with Celery/Redis for Background Tasks 26- Caching Layers (Redis) and Database Query Optimization 27- Microservices Patterns and API Gateways 28- Building a Full-Stack CRUD App with User Auth and File Handling 29- API Analytics, Logging (Structlog), and Error Tracking 30- Code Reviews, Maintainability, and Evolving APIs in Production

Sales Campaign

Sales Campaign

We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.