AWS EC2 - Elastic Compute Cloud Explained
Amazon EC2 (Elastic Compute Cloud) is one of the most popular AWS services that provides virtual servers (called instances) in the cloud. You can launch Linux or Windows machines on demand, deploy your applications, and pay only for the compute power you use.
What is EC2?
EC2 is a cloud service that lets you create and manage virtual servers. These servers come with CPU, RAM, storage, and networking capabilities like a physical machine, but without owning any hardware. You can launch, scale, or delete instances within seconds.
AWS even provides free-tier eligible instances (like t2.micro or t3.micro) for the first 12 months, making it perfect for beginners.
Why use EC2 instead of physical servers?
- No hardware purchase or maintenance
- Launch servers in minutes
- Scale up or down instantly
- Pay only while the instance is running
- Highly reliable and secure AWS infrastructure
Key EC2 Concepts: AMI, Instance Type, Key Pair, Security Group
1. AMI (Amazon Machine Image)
An AMI is like a template used to launch EC2 instances. It includes:
- Operating system (Amazon Linux, Ubuntu, Windows)
- Base packages
- Pre-installed software
Choosing an AMI is like selecting which OS to install on a laptop.
2. Instance Types
Instance types define the hardware specifications of your virtual server:
- vCPUs
- RAM
- Network performance
Examples (T2 family):
- t2.nano – 1 vCPU, 0.5 GB RAM
- t2.micro – 1 vCPU, 1 GB RAM (✔ Free Tier)
- t2.small – 1 vCPU, 2 GB RAM
- t2.medium – 2 vCPUs, 4 GB RAM
Other instance families:
- C-series – Compute optimized
- R-series – Memory optimized
- I/D-series – Storage optimized
3. Key Pair
A key pair is used for secure SSH login:
- Public key stored on AWS
- Private key (.pem) downloaded to your computer
You MUST store the private key safely. AWS will not allow downloading it again later.
4. Security Group
A security group is a virtual firewall that controls traffic to your EC2 instance.
Common rules:
- Port 22 – SSH
- Port 80 – HTTP
If port 80 is blocked, your website won’t load. If port 22 is blocked, you cannot SSH into the instance.
Storage & User Data
EBS Volume (Storage)
- Acts like the SSD/HDD of your virtual machine
- You can choose size (e.g., 8 GB) and type (gp3 SSD)
User Data
User-data scripts run automatically when the instance launches. Example script to install Apache:
Welcome to my EC2 website
" > /var/www/html/index.htmlHow to Launch and Test an EC2 Instance
- Open the AWS console → EC2 → Launch Instance
- Set instance name (example: "my-first-ec2")
- Choose an AMI (Amazon Linux 2023)
- Select instance type (t2.micro)
- Create/select a key pair
- Configure security group (SSH + HTTP)
- Add user data (Apache installation script)
- Launch
After it is running:
- Copy the public IP
- Paste it in a browser
- You will see your HTML page served by Apache
Connecting to EC2 via SSH
On Linux/Mac Terminal
On Windows
Use PuTTY with the converted key (.ppk).
Cleaning Up
- Stop Instance – stops billing for compute
- Terminate Instance – deletes permanently
What’s Next?
Now that you understand EC2 basics — AMI, instance types, security groups, SSH — you are ready to deploy your Spring Boot application on EC2.
The next tutorial: Running Spring Boot on an EC2 instance and exposing it to the internet.
Comments
Post a Comment