<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mshadab Dev on Medium]]></title>
        <description><![CDATA[Stories by Mshadab Dev on Medium]]></description>
        <link>https://medium.com/@mshadab.dev?source=rss-0ce956973d91------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Vj9b5hwCniqxo3ug</url>
            <title>Stories by Mshadab Dev on Medium</title>
            <link>https://medium.com/@mshadab.dev?source=rss-0ce956973d91------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 12:42:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mshadab.dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Built a Production Full-Stack App on AWS for Under $5/Month]]></title>
            <link>https://medium.com/@mshadab.dev/how-i-built-a-production-full-stack-app-on-aws-for-under-5-month-3a1067423d3a?source=rss-0ce956973d91------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a1067423d3a</guid>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[cost-effective]]></category>
            <dc:creator><![CDATA[Mshadab Dev]]></dc:creator>
            <pubDate>Fri, 27 Feb 2026 18:57:17 GMT</pubDate>
            <atom:updated>2026-02-27T20:09:31.638Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>FastAPI + Mangum on Lambda, API Gateway, and Amplify with Free Neon Postreges and Free R2 Cloud Storage — The Serverless Stack That Actually Works</strong></h3><p>I’ve been building SaaS products for over a decade. In that time, I’ve watched teams burn through thousands of dollars a month on infrastructure for apps that serve a few hundred users. EC2 instances idling at 3 AM. ECS clusters over-provisioned “just in case.” Kubernetes clusters that cost more in DevOps hours than the compute itself.</p><p>When I set out to build an influencer marketing platform — a system with a REST API, background workers, scheduled jobs, a database, and a modern React frontend — I wanted to prove that you don’t need any of that. Not at the start. Not even at moderate scale.</p><p><strong>The result: a production full-stack application running on AWS for under $5/month at low-to-moderate traffic.</strong></p><p>— -</p><h4>The Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwJka1f-cyGuHl0Md8vLag.png" /></figure><p>The frontend is a React (or Next.js) app hosted on <strong>AWS Amplify</strong>. Every API call hits <strong>API Gateway HTTP API v2</strong>, which proxies to a <strong>Lambda function</strong> running <strong>FastAPI</strong> via the <strong>Mangum</strong> adapter. Background jobs use <strong>EventBridge</strong> for scheduling and <strong>SQS</strong> for fan-out processing — each backed by its own Lambda.</p><p>— -</p><p><strong>Why This Stack?</strong></p><p><strong>FastAPI + Mangum on Lambda</strong></p><p>FastAPI is one of the fastest Python web frameworks — async-native, auto-generating OpenAPI docs, with built-in Pydantic validation and dependency injection. The problem is that Lambda expects a handler function, not an ASGI server.</p><p><strong>Mangum</strong> bridges that gap. It’s a lightweight adapter that translates API Gateway events into ASGI requests, feeds them to FastAPI, and converts the response back. Your Lambda integration is literally one line: `handler = Mangum(app)`.</p><p>The beauty is that <strong>the same codebase runs locally with Uvicorn and in production on Lambda</strong> with zero changes. Your business logic, data access, validation — all of it is framework-agnostic and portable.</p><p><strong>API Gateway HTTP API v2</strong></p><p>This is the newer, leaner version of API Gateway. A single catch-all route (`<em>ANY /{proxy+}</em>`) forwards everything to Lambda, and FastAPI handles all routing internally.</p><p>Why v2 over the classic REST API?</p><p>- <strong>71% cheaper</strong> — $1.00/million requests vs $3.50/million</p><p>- <strong>Lower latency</strong> — ~5ms overhead vs ~10ms</p><p>- <strong>Built-in JWT authorizers</strong> — no custom Lambda authorizer needed</p><p>- <strong>Built-in CORS </strong>— configured at the gateway level</p><p>Unless you specifically need REST API features like API keys or usage plans, v2 is the obvious choice.</p><p><strong>AWS Amplify for Frontend</strong></p><p>Amplify Hosting is criminally underrated for frontend deployment:</p><p>- <strong>Git-based CI/CD</strong> — push to `main`, it builds and deploys automatically</p><p>- <strong>Custom domains with free SSL</strong> — zero certificate management</p><p>- <strong>SPA rewrites</strong> — critical for React Router; all paths resolve to `index.html`</p><p>- <strong>Preview branches</strong> — PR previews out of the box</p><p>- <strong>SSR support</strong> — Next.js runs on Lambda@Edge at the CDN edge</p><p>For a React + Vite SPA, you configure the build command (<em>npm run build</em>), the output directory (<em>dist</em>), and point your domain. For Next.js SSR, Amplify’s <em>WEB_COMPUTE</em> platform handles server-side rendering automatically — still serverless, still pay-per-use.</p><p>— -</p><p><strong>The Dual-Mode Dockerfile</strong></p><p>One of the best developer experience decisions: a single Dockerfile that works for both local development and Lambda deployment.</p><p>The base image is AWS’s official Lambda Python runtime. A conditional entrypoint checks an environment variable: if <em>LOCAL_DEV=1</em>, it boots <strong>Uvicorn with hot-reload</strong> for instant feedback during development. Otherwise, it uses the <strong>Lambda Runtime Interface Client</strong> for production.</p><p>With Docker Compose, `docker compose up` gives you a local API server with hot-reload, an SQS emulator (ElasticMQ), and background workers — all behaving identically to production. No AWS account needed for development.</p><p>— -</p><p><strong>Background Jobs for Free</strong></p><p>Most real applications need async processing. Ours fetches YouTube analytics daily for thousands of creator videos using a fan-out pattern:</p><p>1. <strong>EventBridge</strong> triggers a dispatcher Lambda daily (scheduled rules are free)</p><p>2. The dispatcher queries the database and sends one <strong>SQS</strong> message per task</p><p>3. A worker Lambda processes messages with controlled concurrency (reserved at 20) and a dead-letter queue for failures</p><p>At 10,000 messages/day, the entire pipeline costs $0.00 — well within free tiers for Lambda, SQS, and EventBridge.</p><p>— -</p><p><strong>Infrastructure as Code with Terraform</strong></p><p>Every piece of infrastructure — Lambda functions, API Gateway, Amplify apps, SQS queues, EventBridge rules, IAM roles, custom domains — is defined in Terraform. The entire stack can be torn down and recreated in minutes.</p><p>Key configuration decisions:</p><p>- <strong>Lambda: 256 MB memory, 30s timeout</strong> — FastAPI is lightweight; this keeps costs minimal since pricing is proportional to memory x duration</p><p>- <strong>VPC attachment</strong> for RDS access (adds 2–5s cold start; skip if using DynamoDB)</p><p>- <strong>ZIP deployment via S3</strong> — a build script installs dependencies for the Lambda Linux runtime, zips everything, and uploads to S3</p><p>- <strong>Throttling</strong> at the API Gateway level — 100 burst, 50 sustained requests/second</p><p>— -</p><p><strong>Drop RDS — Use Neon Postgres for Free</strong></p><p>The single biggest line item in this stack is the database. AWS RDS, even at the smallest `<em>db.t4g.micro</em>` tier, costs ~$12/month. That’s over 90% of the total bill.</p><p>The fix: <strong>use Neon instead of RDS.</strong></p><p>[Neon](https://neon.tech) is a serverless Postgres provider with a genuinely generous free tier — 100 projects, 100 compute-hours/month, 0.5 GB storage, autoscaling up to 8 GB RAM, branching, and read replicas. No credit card required.</p><p>For an early-stage app, this is more than enough. You get a fully managed Postgres instance with connection pooling, and your Lambda functions connect to it over the public internet — which means <strong>you no longer need VPC attachment on your Lambda</strong>. Dropping VPC eliminates the 2–5 second cold start penalty entirely.</p><p>The connection string swap is trivial — replace the RDS `DATABASE_URL` with Neon’s pooled connection string, and everything else stays the same. FastAPI, SQLAlchemy, Alembic migrations — they all work identically because it’s still standard Postgres underneath.</p><p><strong>Drop S3 — Use Cloudflare R2 for Object Storage</strong></p><p>If your app needs file uploads — profile images, documents, media — the instinct is to reach for AWS S3. But S3’s dirty secret is <strong>egress fees</strong>. Storing files is cheap ($0.023/GB), but every time a user downloads a file, AWS charges $0.09/GB for data transfer out. For media-heavy apps, this adds up fast.</p><p><strong>Cloudflare R2</strong> is S3-compatible object storage with one killer difference: <strong>egress is completely free.</strong> Zero data transfer charges, no matter how much your users download.</p><p>R2’s free tier is generous enough for most early-stage apps — 10 GB storage, 1 million Class A operations (writes), 10 million Class B operations (reads), and free egress, every month. Beyond free tier, storage is $0.015/GB-month — still cheaper than S3.</p><p>Since R2 is S3-compatible, your existing code using `boto3` works with a one-line config change — just point the endpoint URL to your R2 bucket. Pre-signed URLs, multipart uploads, bucket policies — it all works the same way. And because R2 sits behind Cloudflare’s CDN, your files are served from edge locations globally without needing a separate CloudFront distribution.</p><p><strong>The Real Cost Breakdown</strong></p><p>For a production app serving ~100K API requests/month and ~50K frontend page views/month:</p><p>| Service | Monthly Cost |</p><p>| — — — — -| — — — — — — -|</p><p>| Lambda (API + Workers) | <strong>$0.00</strong> (free tier: 1M requests) |</p><p>| API Gateway HTTP API | <strong>$0.00</strong> (free tier: 1M requests) |</p><p>| Amplify Hosting | <strong>$0.00</strong> (free tier: 15GB served) |</p><p>| SQS | <strong>$0.00</strong> (free tier: 1M requests) |</p><p>| EventBridge | <strong>$0.00</strong> (scheduled rules are free) |</p><p>| Neon Postgres | <strong>$0.00</strong> (free tier: 100 compute-hrs) |</p><p>| Cloudflare R2 | <strong>$0.00</strong> (free tier: 10GB + free egress) |</p><p>| CloudWatch + Route 53 | <strong>~$1.00</strong> |</p><p>| <strong>Total</strong> | <strong>~$1.00/month</strong> |</p><p>That’s not a typo. A production full-stack application — API, frontend, database, background jobs, scheduled tasks — for <strong>a dollar a month.</strong></p><p>Compare to a traditional setup — EC2 ($15) + ALB ($16) + ECS Fargate ($30) + RDS ($12) + Vercel Pro ($20) = <strong>$93+/month</strong> for equivalent functionality.</p><p>— -</p><p><strong>Honest Trade-offs</strong></p><p><strong>Cold starts</strong> are real. With VPC-attached Lambdas (needed for RDS), cold starts can hit 2–5 seconds. By switching to Neon and dropping VPC, cold starts drop to ~500ms-1s. If even that matters, provisioned concurrency (~$15/month for 5 warm instances) eliminates it entirely.</p><p><strong>Request duration limits.</strong> API Gateway times out at 30 seconds. For long-running tasks (video processing, large uploads), use pre-signed S3 URLs or Step Functions.</p><p><strong>WebSockets</strong> require a different programming model on Lambda. For real-time features, consider AppSync or a dedicated WebSocket API.</p><p>— -</p><p><strong>When to Graduate</strong></p><p>Once you’re consistently hitting <strong>1M+ requests/month</strong> and cold starts are impacting user experience, consider:</p><p>- <strong>Provisioned concurrency</strong> — still serverless, just pre-warmed</p><p>- <strong>ECS Fargate</strong> — container-based, always-on, still managed</p><p>- <strong>EKS</strong> — only if you truly need Kubernetes</p><p>The key insight: <strong>your application code doesn’t change when you migrate.</strong> FastAPI runs the same on Lambda, Fargate, or bare EC2. Mangum is the only Lambda-specific piece, and removing it is deleting one line.</p><p>— -</p><p><strong>Key Takeaways</strong></p><p>1. <strong>FastAPI + Mangum</strong> gives you a world-class API framework that deploys to Lambda with a single-line adapter.</p><p>2. <strong>HTTP API Gateway v2</strong> is 71% cheaper than REST API v1 — always choose v2 unless you need specific v1 features.</p><p>3. <strong>One Dockerfile, two modes</strong> — Uvicorn for local dev, Lambda RIC for production. Same image, same behavior.</p><p>4. <strong>Amplify is free hosting</strong> for most SPA and SSR apps, with git-push deploys and custom domains.</p><p>5. <strong>EventBridge + SQS + Lambda</strong> gives you a complete async processing pipeline at zero cost for moderate workloads.</p><p>6. <strong>Start serverless, graduate when needed.</strong> Don’t pay for infrastructure you don’t need yet. Your code is portable — the migration path is always open.</p><p>— -</p><p><strong><em>The best infrastructure is the infrastructure you don’t pay for.</em></strong></p><p>— -</p><p><strong>Tags:</strong> `#AWS` `#FastAPI` `#Serverless` `#Lambda` `#Amplify` `#Python` `#FullStack` `#Mangum` `#Terraform` `#StartupEngineering`</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a1067423d3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>