I wrote this like I would explain to a junior in a lab session. No heavy words, no theory overload. Just what matters when you actually create and use an EC2 machine.
Small intro
When we say "EC2," think of one thing: a computer on rent. You do not buy hardware. You open AWS, pick a machine size, and start using it.
That is why most people start cloud learning with EC2.
1) What is EC2?
EC2 stands for Elastic Compute Cloud.
Simple meaning:
- It is a virtual server in AWS.
- You can install software in it like your own laptop.
- You can run website, backend API, database, scripts, anything.
Why "Elastic"?
Because you can scale up or down based on traffic.
If today only 10 users come, small server is enough.
If tomorrow 10,000 users come, you can move to bigger machine or add more machines.
2) EC2 pricing model (the part everyone asks first)
AWS gives multiple payment options. Choose based on your situation.
On-Demand
Use and pay. No long commitment.
Best for:
- Learning
- Demo
- Testing new features
Reserved Instances
You commit for long term (usually 1 or 3 years).
Cost is lower than on-demand.
Best for:
- Stable production apps
- Predictable workloads
Spot Instances
Very cheap (sometimes huge discount), but AWS can reclaim it.
Best for:
- Batch jobs
- Video processing
- Non-critical tasks Not best for always-on production.
Savings Plans
You commit to a certain usage/spend level over time.
Good discount and some flexibility.
Quick student rule:
- New to AWS -> start On-Demand.
- Predictable long-term app -> compare Reserved/Savings.
- Cost-first experiments -> try Spot.
3) Instance families (machine categories)
All EC2 machines are not same. AWS groups them by purpose.
General purpose
Balanced CPU + RAM.
Example family: T series, M series.
Good for normal web apps and learning.
Compute optimized
More CPU power.
Example family: C series.
Good for CPU-heavy tasks like rendering, transforms, game servers.
Memory optimized
More RAM.
Example family: R series.
Good for cache/database memory-heavy apps.
Storage optimized
Fast/high-throughput disk access.
Example family: I series.
Good for data-intensive workloads.
A common beginner pick is t3.micro or t2.micro style instance (based on region/free-tier rules).
4) What is AMI image?
AMI means Amazon Machine Image.
AMI is like a prebuilt template used to launch an EC2 instance.
It contains:
- OS (Ubuntu, Amazon Linux, Windows, etc.)
- Base config
- Sometimes preinstalled tools
Two common types:
- Public AMI: provided by AWS or marketplace/community
- Private AMI: custom image prepared by your org/team
Easy memory trick: AMI is the "starter pack" for your EC2 machine.
5) SSH, public key, private key (important)
When you connect to Linux EC2, usually you use SSH.
You create/use a key pair:
- Public key -> placed on server side
- Private key (
.pem) -> stays only with you
Never share private key. Ever.
If private key leaks, server access risk is high.
Basic command:
ssh -i mykey.pem ubuntu@<EC2_PUBLIC_IP>
Common usernames:
- Ubuntu AMI ->
ubuntu - Amazon Linux ->
ec2-user
If permission issue comes for key file, set strict permission:
chmod 400 mykey.pem
6) Install Nginx and host first static file in /var/www/html
Assume Ubuntu EC2.
Install and start Nginx
sudo apt update
sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
Put first static page
echo "<h1>My first EC2 static page</h1>" | sudo tee /var/www/html/index.html
Now open:
http://<EC2_PUBLIC_IP>
If port 80 is open in Security Group, page will load.
7) Flask Hello World host on port 8080 + Security Group
Install Python + Flask
sudo apt update
sudo apt install -y python3 python3-pip
pip3 install flask
Create app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World from Flask running on EC2"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
Run it
python3 app.py
Security Group for port 8080
In AWS Console:
- EC2 -> Instances -> select your instance
- Security -> click Security Group
- Inbound rules -> Edit inbound rules
- Add rule:
- Type: Custom TCP
- Port: 8080
- Source: 0.0.0.0/0 (only for demo/testing)
Now test in browser:
http://<EC2_PUBLIC_IP>:8080
You should see your hello message.
Production note:
Do not keep wide-open rules forever. Restrict CIDR, use reverse proxy, and enable HTTPS.
One-page final summary
EC2 is a cloud server you can rent in minutes.
You choose pricing model based on your budget and stability needs.
Instance families help you pick the right machine for CPU, memory, or storage focus.
AMI is the base image used to launch the instance.
SSH key pair is how you securely log in.
Nginx helps you host static pages from /var/www/html.
Flask can run on port 8080, and you must allow that port in Security Group.
If you can do these steps once by yourself, you already have strong EC2 fundamentals.
Top comments (0)