Chapter 20: AWS Lambda

AWS Lambda, the heart and soul of serverless computing on AWS.

If you’ve been following our journey so far (EC2 → Auto Scaling → Load Balancing → Messaging → Serverless intro), Lambda is where the magic really happens: you stop renting and managing servers forever and just write code that runs when something interesting occurs.

Let me explain it like we’re sitting together with a notebook and a second cup of chai — slow, detailed, full of real analogies, Hyderabad/India examples, how it works in 2026, pricing reality, common patterns, limitations, and a simple hands-on you can do right now.

1. What is AWS Lambda? (Simple + Official Definition – 2026)

AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers.

  • You upload your code (called a function)
  • You tell Lambda when to run it (triggers / events)
  • Lambda executes your code in an isolated environment
  • You pay only for the compute time used (billed in milliseconds)
  • When no events happen → zero cost and zero infrastructure

Official short line (from aws.amazon.com/lambda/): “AWS Lambda is a compute service that lets you run code without provisioning or managing servers. Lambda automatically scales from zero to thousands of requests per second.”

In plain Hyderabad language: Instead of keeping a laptop/computer (EC2 instance) switched on 24/7 waiting for work, you give AWS a small piece of code and say: “Run this only when someone uploads a photo, or when an order is placed, or every 5 minutes, or when someone hits my API.” AWS wakes up a tiny container just for that moment, runs your code, sends the result, then shuts everything down. You pay ₹0.000 something per second of actual running time.

2. How Lambda Actually Works (Step-by-Step – 2026 View)

  1. You write a function
    • Supported languages: Node.js, Python, Java, Go, .NET, Ruby, custom runtimes (even Deno, Rust via layers)
    • Code + dependencies (packaged as ZIP or container image)
  2. You configure triggers (events that invoke Lambda)
    • API Gateway (HTTP requests)
    • S3 (file upload/delete)
    • DynamoDB streams / EventBridge / SQS / SNS
    • CloudWatch Events / Scheduled (cron-like)
    • Alexa, IoT, Step Functions, etc. (200+ AWS sources)
  3. Invocation happens
    • Event arrives → Lambda creates execution environment (if cold)
    • Your code runs with event data as input
    • Returns response or side-effects (write to DB, publish SNS, etc.)
  4. Execution environment lifecycle
    • Cold start: First run or after idle → 100 ms – few seconds (depends on language/size)
    • Warm: Subsequent calls reuse environment → <100 ms
    • Provisioned Concurrency / SnapStart → eliminate cold starts (pay extra)
  5. AWS cleans up → environment destroyed after idle → zero cost

3. Key Limits & Features (Important to Know in 2026)

Feature / Limit Value (2026) Notes / Workaround
Max execution time 15 minutes Use Step Functions for longer workflows
Memory (RAM) 128 MB – 10,240 MB CPU scales with memory (more RAM = faster CPU)
Ephemeral disk (/tmp) Up to 10,240 MB Good for temp files
Concurrent executions (default) 1,000 per region Request increase (free)
Payload size (sync) 6 MB request / 6 MB response Use S3 for larger data
Deployment package 250 MB zipped / 10 GB unzipped (container) Use layers or container images
Cold start mitigation Provisioned Concurrency, SnapStart (Java/.NET) Pay for always-warm instances

4. Pricing in 2026 (ap-south-1 Mumbai – Very India-Friendly)

  • Free tier (forever):
    • 1 million requests/month
    • 400,000 GB-seconds compute time/month
  • Beyond free:
    • Requests: $0.20 per 1 million (~₹16–17 per million)
    • Duration: $0.00001667 per GB-second (~₹0.0014 per GB-second)
    • Example: 512 MB function runs 200 ms → 0.1024 GB-seconds → cost ≈ ₹0.00014 per invocation

Realistic bill example (small Hyderabad startup):

  • 500,000 API calls/month
  • Average 400 ms duration, 512 MB memory
  • Compute: ~20,480 GB-seconds → ~₹28
  • Requests: ~₹8
  • Total: ₹40–100/month (after free tier often ₹0)

Compare to EC2 t3.micro 24/7 (~₹1,500–2,000/month) — serverless wins big on variable/low traffic.

5. Real Hyderabad Example: Serverless Image Thumbnail Generator

Your college project / startup photo-sharing app:

Goal: When user uploads photo to S3 → automatically create thumbnail + store it.

Serverless flow (no servers):

  1. User uploads photo.jpg to S3 bucket “hyderabad-photos”.
  2. S3 event notification → triggers Lambda function “CreateThumbnail”.
  3. Lambda code (Python example):
    • Receives event with bucket/key
    • Downloads photo from S3
    • Uses Pillow library to resize to 200×200
    • Uploads thumbnail-200.jpg back to S3
    • (Optional) Publishes to SNS “thumbnail created” → send push notification
  4. Done in ~300–800 ms
  5. During viral moment (10,000 uploads/hour) → Lambda scales to thousands of concurrent executions automatically
  6. At night → zero invocations → ₹0

Cost: Usually ₹50–300/month even with moderate usage — vs running EC2 instance 24/7.

6. Quick Hands-On (Free Tier – Do This in 10 Minutes!)

  1. Go to Lambda console → Create function → “Author from scratch”
  2. Name: “HelloHyderabad2026”
  3. Runtime: Python 3.12 or Node.js 20
  4. Code (Python example):
Python
  1. Create test event → empty JSON → Test → see output
  2. (Bonus) Add API Gateway trigger → get public URL → open in browser!

Cost? ₹0 (inside free tier).

Summary Table – Lambda Cheat Sheet (2026)

Question Answer (Beginner-Friendly)
What is Lambda? Serverless functions — run code without servers
When does it run? Triggered by events (S3, API Gateway, DynamoDB, SQS, etc.)
Pay for? Requests + compute duration (ms) — idle = ₹0
Max runtime? 15 minutes
Cold start? Yes — mitigated with Provisioned Concurrency / SnapStart
Best for? Event-driven tasks, APIs, background jobs, variable traffic
First project idea? S3 upload → thumbnail generator, API backend, cron jobs

Lambda is the “just write code and let AWS handle the rest” service — the foundation of almost every modern serverless app in Hyderabad 2026.

Got it? Want next:

  • Deep dive on cold starts & how to kill them?
  • Full serverless CRUD API (API Gateway + Lambda + DynamoDB)?
  • Lambda vs Fargate vs EC2 comparison?

Tell me — next lesson is ready! 🚀⚡

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *