Published on: 2022-06-02
Serverless is no longer the new kid on the block. Itβs a go-to choice for startups, hobby projects, and even large-scale systems thanks to its scalability, simplicity, and cost-efficiency.
But what actually happens behind the scenes when you build a serverless application on AWS?
Letβs break it down β visually.
π What Happens When You Hit an API Endpoint?
Hereβs the typical flow for a serverless REST API built on AWS:
π Breakdown of Each Component
- Client β A frontend app (e.g., React, Vue) or tool like Postman makes an HTTP request.
- API Gateway β Manages routing, validation, and throttling. Itβs the entry point to your backend.
- Lambda Function β Runs your business logic on-demand. You pay only per execution.
- Auth Layer β Optionally uses Amazon Cognito or custom JWT validation.
- DynamoDB β AWSβs NoSQL database. Super fast, serverless, and low-cost.
- S3 β Stores static files like images, docs, etc.
- Return JSON Response β API Gateway wraps the Lambdaβs return and sends it back to the client.
π What Youβd Typically Use in Stack
| Purpose | Tool |
|---|---|
| API Routing | AWS API Gateway |
| Function Logic | AWS Lambda (TypeScript) |
| Database | DynamoDB / Aurora Serverless |
| Auth | Amazon Cognito or JWT |
| Deployment | Serverless Framework / CDK |
| Local Dev | serverless-offline |
β Why Go Serverless?
- π« No server to maintain
- β‘ Scales automatically
- πΈ Pay-per-use model (free tier is generous!)
- π§± Modular β connect to other AWS services easily
- π¦ Great fit for microservices or event-driven apps
π¦ Real-World Example: TODO App
In our recent blog on building a TODO app, we used:
- API Gateway for endpoints like
POST /todos - Lambda (with TypeScript) for logic
- DynamoDB for storing tasks
- JWT for securing access
All deployed with the Serverless Framework, and tested locally using serverless-offline.
π§ͺ Bonus: Test It All Locally
If youβre building serverless apps, donβt skip local development:
npm install serverless-offline serverless-dynamodb-local --save-dev
npx serverless offline start
Now you can hit http://localhost:3000/todos just like itβs live β no AWS deploy needed until youβre ready.
π Summary
Serverless architecture is production-ready, beginner-friendly, and deeply integrated with AWS tooling. If youβre building something lightweight or fast-moving, to embrace the power of Lambda + DynamoDB.
π TL;DR
- Use API Gateway + Lambda for logic
- Use DynamoDB for data
- Use Cognito or JWT for auth
- Use
serverless-offlinefor fast local dev - Deploy with the Serverless Framework
And draw diagrams with Mermaid to impress your future self β¨