EC2 stands for Elastic Compute Cloud, and it is basically AWS’s way of giving us a virtual machine in the cloud.
Instead of buying a physical server, setting it up, and maintaining it manually, EC2 lets us launch a server in minutes. In this blog, I want to share the exact flow I learned for creating and working with an EC2 instance step by step.
What is EC2?
EC2 is a cloud-based virtual server service. It allows us to create a machine, choose its operating system, define CPU and memory size, attach storage, control network access, and connect to it remotely.
The word elastic means the server can scale up or down. For example, if a small machine is not enough, we can later change it to a bigger one.
Why EC2 is Important
EC2 is important because it teaches many basic cloud concepts together:
- Virtual machines
- Public and private IP addresses
- Storage volumes
- Firewall rules
- SSH access
- Elastic scaling
Before Launching an EC2 Instance
One good practice I learned is that we should not just randomly click “Launch Instance.” Before creating any server, we should first gather the requirements.
Step 1: Gather the Requirements
Before launching, decide the following:
- Which operating system is needed
- How much CPU and RAM are required
- How much storage is needed
- What application or service will run on it
- Which environment it belongs to: Dev, QA, Staging, or Production
- Who will manage or own the server
This step helps us choose the correct AMI, instance type, storage, security group, and naming convention.
Step 2: Create the Key Pair
A key pair is used for logging into the EC2 instance. For Linux instances, this is mainly used for SSH access.
The clean way is to create the key before launching the server.
- Go to EC2
- Open Key Pairs
- Click Create Key Pair
- Give it a proper name using a naming convention
- Choose .pem if using Mac, Linux, or Git Bash
- Download and store it safely
A good naming style could be based on project, environment, and region, so the key is easier to identify later.
Step 3: Create the Security Group
A security group works like a firewall. It controls which traffic is allowed to enter or leave the server.
- Go to Security Groups
- Click Create Security Group
- Give it a proper name
- Add an inbound rule for SSH on port 22
- Use My IP as the source for secure access
At this stage, only add rules that are actually needed. If the web server is not running yet, there is no point in opening HTTP access early.
I also learned not to allow “all traffic from anywhere” unless there is a very specific reason, because that removes meaningful protection.
Launching the EC2 Instance
Step 4: Open the EC2 Launch Wizard
- Go to EC2 Dashboard
- Click Launch Instance
Step 5: Add a Name and Tags
Give the instance a clear name such as web01. Then add useful tags like:
- Name
- Project
- Environment
- Owner
Tags help with identification, filtering, organization, and billing.
Step 6: Choose the AMI
The AMI, or Amazon Machine Image, is the operating system template for the server.
Examples include:
- Ubuntu
- Amazon Linux
- Windows Server
In my learning, Ubuntu and Amazon Linux were common starting options, especially for free tier practice.
Step 7: Choose the Instance Type
The instance type defines the machine size, including CPU and memory.
For practice, a free-tier option like t2.micro is a safe and common choice.
Step 8: Select the Key Pair
Choose the key pair created earlier. This is the key that will later be used to log in to the instance.
Step 9: Configure Network Settings
Here we select the security group created earlier so that SSH access is allowed from our own IP.
Step 10: Configure Storage
Most Linux AMIs come with a default volume, often around 8 GB. This storage is provided through EBS, which stands for Elastic Block Store.
This volume works like the virtual hard disk of the machine and stores the operating system and application data.
Step 11: Launch the Instance
Once the configuration is ready, click Launch Instance.
After a short wait, the instance moves into the Running state.
Connecting to the EC2 Instance
Step 12: Copy the Public IP
After launch, the instance gets a public IP and a private IP.
- Private IP stays fixed while the instance exists
- Public IP changes if the instance is stopped and started again
Step 13: SSH into the Server
For a Linux machine, connect using SSH from terminal or Git Bash.
ssh -i your-key.pem ubuntu@your-public-ip
If the AMI is Ubuntu, the username is usually ubuntu. For Amazon Linux, it is commonly ec2-user.
Step 14: Switch to Root User
sudo -i
This gives administrative access so packages and services can be managed more easily.
Installing a Web Server
Step 15: Update Packages and Install Apache
On Ubuntu:
apt update && apt install apache2 -y
On Amazon Linux:
dnf install httpd -y
Step 16: Check the Service Status
On Ubuntu:
systemctl status apache2
On Amazon Linux:
systemctl status httpd
This confirms whether the web server is active and running.
Step 17: Deploy Website Files
After installing the web server, website files can be downloaded, unzipped, and copied into the default web root directory.
For example:
- Install unzip if needed
- Download template files
- Extract them
- Copy them into
/var/www/html
Step 18: Restart the Web Service
On Ubuntu:
systemctl restart apache2
On Amazon Linux:
systemctl restart httpd
Opening the Website to the Public
Step 19: Understand Why the Site May Not Open Yet
Even if Apache is running, the website may still not open in the browser because the security group only allows SSH so far.
Step 20: Add HTTP Rule in Security Group
- Go to the instance
- Open the linked security group
- Edit inbound rules
- Add HTTP on port 80
- Allow from anywhere if the site is meant for public access
After saving the rule, the website can be accessed through the public IP in the browser.
Important EC2 Concepts I Learned
1. Public IP vs Private IP
The private IP stays with the instance, but the public IP can change after stop and start.
2. Elastic IP
If a static public IP is needed, AWS provides Elastic IP. It can be allocated and attached to the instance, but it should be released when not needed because it may create charges.
3. Network Interface
The instance’s networking details such as private IP, public IP, Elastic IP, and security groups are attached to the network interface.
4. Volume
Each EC2 instance comes with a storage volume, usually an EBS volume. This acts as the disk for the machine.
5. Instance Type Can Be Changed
If the machine needs more resources later, the instance type can be changed after stopping the instance first.
6. Termination Protection
AWS also provides termination protection, which helps prevent accidental deletion of important instances.
Cleanup Matters Too
One thing I found important while learning AWS is cleanup. After practice, resources should be removed properly to avoid unnecessary costs.
- Terminate unused instances
- Release unused Elastic IPs
- Keep track of volumes and security groups
Final Thoughts
Learning EC2 taught me much more than just launching a server. It helped me understand how cloud infrastructure is built step by step: compute, networking, storage, security, access, and scaling.
What I liked most is that EC2 is practical. It is not just theory. You can launch a server, connect to it, install software, deploy a site, and understand how real cloud environments work.
For me, EC2 feels like one of the best starting points in AWS because it introduces the foundation of cloud in a hands-on way.
Back to Blogs