What is EC2?
- Amazon EC2 (Elastic Compute Cloud) is a service that provides resizable virtual servers (instances) in the AWS cloud.
- Think of it as renting computers from AWS that you can use anytime, scale up or down, and pay only for the time you use.
Example: Instead of buying a physical server for hosting a website, you can launch an EC2 instance (say, running Linux or Windows) and deploy your website there.
Key Features of EC2
-
Virtual Servers (Instances)
- You can launch servers with different CPU, memory, and storage configurations.
- Types: General purpose, Compute-optimized, Memory-optimized, GPU-based, Storage-optimized.
lets go deeper into it
- An EC2 instance = a virtual computer in the cloud.
- You can choose how powerful your computer should be:
- General purpose → balanced (good for websites, small apps).
- Compute-optimized → more CPU power (good for gaming servers, AI computations).
- Memory-optimized → more RAM (good for databases).
- GPU-based → special graphics processors (good for AI, machine learning, video rendering).
- Storage-optimized → fast disk (good for big data apps).
Example:
Imagine you want to host a personal blog → you don’t need a super powerful server, just a t2.micro (general purpose).
But if you want to train a machine learning model, you’ll need a GPU instance.
-
Elasticity
- Scale up or down within minutes.
- Example: Add more instances during Black Friday sale traffic, then reduce after.
- Elasticity means you can increase or decrease your server capacity within minutes.
- If you get lots of users suddenly, you can add more servers.
- When traffic goes down, you can remove servers (and save money).
Example:
An online store gets 1,000 visitors daily.
But on Black Friday, it gets 100,000 visitors.
- Solution: Add 10 more EC2 servers just for that day.
- After the sale, shut them down → only pay for what you used.
-
Multiple OS Choices
- Linux, Windows, Ubuntu, Red Hat, Amazon Linux, etc.
- On EC2, you can run any operating system you like:
- Linux (Ubuntu, Red Hat, Amazon Linux) → popular for web servers.
- Windows Server → good if your apps depend on Microsoft tools.
Example:
If you’re a Python/Django developer, you might use Ubuntu.
If your company uses .NET apps, you’ll need Windows Server
-
Storage Options
- EBS (Elastic Block Store): Persistent disk storage (like a hard drive).
- Instance Store: Temporary storage (data lost when instance stops).
EC2 gives you two main storage types:
- EBS (Elastic Block Store) → like a hard drive that remembers data even if server is stopped.
- Best if you need to keep files (databases, logs, apps).
- You can even detach and reattach it to another EC2.
- Instance Store → like a temporary hard drive.
- Very fast but data is deleted when the server stops.
- Good for caching or temporary files.
Example:
- If you’re hosting a blog → use EBS to store posts & images safely.
- If you’re running a video encoding job → use Instance Store for temporary raw files.
-
Networking
- Integrated with VPC (Virtual Private Cloud).
- You can assign public/private IPs, configure firewalls (security groups).
- EC2 integrates with VPC (Virtual Private Cloud) → your private network inside AWS.
- You can:
- Give your server a public IP (so the internet can reach it).
- Or keep it private (for internal use only).
- Control traffic using Security Groups (like a firewall).
Example:
- Web server → needs public IP so users can access it.
- Database server → should have private IP so only your web app can talk to it.
-
Pricing Models
- On-Demand: Pay per hour/second.
- Reserved Instances: Cheaper for 1–3 year commitments.
- Spot Instances: Bid for unused capacity at big discounts.
- Savings Plans: Flexible pricing commitments.