What is Serverless?
Serverless does NOT mean “there are no servers.
It means...
You don't manage the servers. AWS manages everything for you.
You only write code, and AWS handles:
- servers
- scaling
- uptime
- patches
- networking
- infrastructure
You pay only when your code runs.
Let's understand with example...
Imagine you want to run a function.
Instead of buying a computer, you ask AWS:
‘Please run this code whenever needed.’
AWS does the rest.
Why Serverless Exists?
Before serverless:
- you must choose server size
- you must keep it running
- you must pay 24/7
- you must scale manually
- you must monitor and reboot
With serverless:
- no servers to manage
- no scaling worries
- no idle costs
- automatically handles millions of users
- ideal for APIs, cron jobs, triggers
What is AWS Lambda?
AWS Lambda is THE most famous serverless service.
Lambda = run your code without servers.
You upload your code → AWS executes it when needed → you pay only for milliseconds used.
How Lambda works???
Event Occurs
|
Lambda (Runs Code)
|
Output
Examples of events that trigger Lambda:
- API call from API Gateway
- File uploaded to S3
- DynamoDB table change
- SNS message
- SQS queue message
- CloudWatch cron job
- IoT event
Let's understand how Lambda executes code internally!
- Firstly, any event happens. Like user hits button or login API.
- Lambda who was sleeping,wakes up!
- User code executes.
- Lambda return results or writes to database.
- Lambda goes for sleep again!(shuts down..no server stays running)
Cold Start vs Warm Start (Important)
When a Lambda function runs, AWS needs to prepare an execution environment for it.
This environment includes:
- CPU + memory allocation
- Runtime setup (Node/Python/Java…)
- Your code loading
- Dependencies loading (npm, libs, etc.)
- Environment variables
- Network setup (VPC ENI if used)
Depending on whether this environment already exists or not, Lambda behaves differently.
COLD START
A cold start happens when:
- It’s the first time Lambda is running
- Lambda hasn’t been used for some time
- Lambda is deployed new version
- AWS scaled up and needed new containers
- You changed VPC settings (most costly cold starts)
Because Lambda doesn’t keep containers alive forever.
It sleeps after inactivity to save cost.
Also when traffic spikes:
If suddenly 1000 users come at once → AWS creates 1000 fresh containers → cold starts for many.
WARM START
A warm start happens when AWS already has a prepared container for your Lambda.
Meaning:
- Lambda ran recently
- AWS kept the container alive (in warm pool)
- No setup needed
- Code executes instantly
AWS keeps Lambda containers warm for some minutes (usually 5–15 minutes), hoping the function will be used again.
Understand with a simple story...
Warm Start - Suppose a gas stove is already hot and you can cook immediately.
Cold Start - Suppose a gas stove is cold and you must light it,heat it and then start cooking.
Lambda vs EC2
| Feature | Lambda | EC2 |
|---|---|---|
| Server Management | None | You manage |
| Pricing | Pay per execution | Pay per hour |
| Scaling | Automatic | Manual/Auto scaling |
| Ideal For | Small bursts, events | Heavy apps, long-running apps |
| Always running? | No | Yes |
| Cold start | Yes | No |
| Control Level | Low | High |
| OS access | No | Yes |
When to Use Lambda?
Use Lambda when:
- You need API endpoints.
- You want event-driven apps.
- You only need code to run occasionally.
- You want low cost.
- You want no server maintenance.
When NOT to Use Lambda?
Use EC2 instead if:
- You need app running 24/7
- You have heavy CPU tasks
- You need custom OS configurations
- You want to host databases or big backend apps
- You need persistent connections (sockets, games, chat servers)
What is the Serverless Framework?
The Serverless Framework is a tool used to create and deploy serverless apps easily.So, instead of:
- creating Lambda manually
- adding triggers manually
- connecting API Gateway manually
- configuring permissions manually
❗ Serverless Framework does everything for you.
File syntax is something like this:
service: my-service
provider:
name: aws
runtime: nodejs18.x
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
Then, we run below command on terminal:
serverless deploy
And boom 💥
It creates:
- Lambda
- API Gateway routes
- Permissions (IAM roles)
- Logs (CloudWatch)
- And deploys everything
Serverless Framework = DevOps Shortcut
It automates:
- Packaging code
- Creating CloudFormation
- Deploying Lambda
- Creating APIs
- Versioning
- Permissions
- Environment variables
- Stages (dev, prod, test)
Very popular in companies for serverless architectures.

Top comments (0)