mediumFull Stack EngineerStartup
AWS S3, CloudFront, and Lambda — how do they work together for serverless?
Posted 18/04/2026
by Mehedy Hasan Ador
Question Details
"Host Next.js static export + API on AWS without managing servers."
Suggested Solution
Stack
S3 (static files) → CloudFront (CDN) → Users, Lambda (API) → API Gateway → CloudFront
// Lambda handler
export const handler = async (event) => {
const apps = await prisma.application.findMany();
return { statusCode: 200, body: JSON.stringify(apps) };
};
// Pay per invocation (~$0.20/1M requests), cold start ~200ms
| Component | Traditional | Serverless |
|---|---|---|
| Compute | $30/mo (always on) | $5/mo (pay per use) |
| CDN + Storage | $10/mo | $6/mo |
| Total | ~$40/mo | ~$11/mo |
Best for variable traffic. Not for constant heavy traffic or long-running processes.