AWS Lambda is a serverless computing service that lets you execute code in response to events, without the need to manage servers. Simply submit your function, define the triggers, and Lambda automatically handles execution, scaling, and availability. Ideal for tasks such as data processing, automation, API backends, and integrations with other AWS services.
💡 You only pay for the time your code runs — there are no downtime charges.
AWS API Gateway is a managed service that makes it easy to build, publish, maintain, and secure RESTful and WebSocket APIs. It acts as a bridge between clients and backend services (such as AWS Lambda), managing traffic, authentication, request throttling, and monitoring.
🔐 Native support for authentication via IAM, Cognito, and API keys, plus direct integration with Lambda for serverless architectures.
Below is an example of a Python project built with Fast API + SQLAlchemy ORM:
import os
from typing import List
from fastapi import FastAPI, Depends, HTTPException
from mangum import Mangum
from dotenv import load_dotenv
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from models import Base, User # Your SQLAlchemy models
from schemas import UserCreate, UserOut, UserUpdate
# Load environment variables
load_dotenv()
# Database configuration
DATABASE_URL = os.getenv("DATABASE_URL")
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base.metadata.create_all(bind=engine)
app = FastAPI()
handler = Mangum(app)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
@app.get("/")
async def health_check():
return {"status": "ok"}
@app.post("/users/", response_model=UserOut)
def create_user(user: UserCreate, db: Session = Depends(get_db)):
db_user = User(**user.dict())
db.add(db_user)
db.commit()
db.refresh(db_user)
return db_user
@app.get("/users", response_model=List[UserOut])
def get_users(db: Session = Depends(get_db)):
users = db.query(User).all()
return users
@app.put("/users/{user_id}", response_model=UserOut)
def update_user(user_id: int, user: UserUpdate, db: Session = Depends(get_db)):
db_user = db.query(User).filter(User.id == user_id).first()
if not db_user:
raise HTTPException(status_code=404, detail="User not found")
for key, value in user.dict(exclude_unset=True).items():
setattr(db_user, key, value)
db.commit()
db.refresh(db_user)
return db_user
@app.delete("/users/{user_id}")
def delete_user(user_id: int, db: Session = Depends(get_db)):
db_user = db.query(User).filter(User.id == user_id).first()
if not db_user:
raise HTTPException(status_code=404, detail="User not found")
db.delete(db_user)
db.commit()
return {"detail": "User deleted"}
Note the last import “from mangum import Mangum”, we use this library to adapt our code to AWS Lambda. Mangum is like the bridge that lets your FastAPI app walk confidently into the world of AWS Lambda. Acts as an adapter between your ASGI-based FastAPI application and AWS Lambda. Since Lambda expects a specific event format and FastAPI runs on ASGI (Asynchronous Server Gateway Interface), Mangum translates between the two.
handler is what AWS Lambda will invoke.