EC2 in AWS
- EC2 (Elastic Compute Cloud) is an AWS service that provides virtual computers/servers in the cloud.
- You can use EC2 to run websites, applications, APIs, databases, and other software.
- You can start, stop, restart, or terminate EC2 servers whenever you need them.
- You generally pay for the AWS resources you use, with pricing depending on the instance and other resources.
What is an EC2 Instance?
- An EC2 Instance is a virtual server/computer created using Amazon EC2.
- It has CPU, RAM, storage, networking, and an operating system.
- You choose an AMI to decide the operating system, such as Ubuntu or Amazon Linux.
- You choose an Instance Type to decide how much CPU and RAM the server gets.
- A Security Group acts like a firewall and controls incoming/outgoing network traffic.
- You can connect to a Linux instance using SSH.
- Each instance can have a private IP, and it can have a public IP when internet access is required.
Simple Example
EC2 = AWS service that provides virtual servers
Instance = One virtual server created inside EC2
How to Create an EC2 Instance in AWS
Think of an EC2 instance as a computer/server that you rent from AWS.
For example:
Your laptop has Windows and you install software on it.
Similarly, an EC2 instance is a computer in the AWS cloud where you can install Linux, Apache, websites, databases, Docker, etc.
Step 1 — Login to AWS
Go to the Amazon Web Services Management Console and log in to your AWS account.
Choose Root user or IAM user-
After logging in, you will see the AWS Management Console.
Step 2 — Open EC2
In the AWS Console:
- Click the Search bar at the top.
- Type EC2.
- Select EC2 from the results.
You will now be inside the EC2 Dashboard.
Step 3 — Choose the AWS Region
At the top-right corner, you will see the current Region.
For example:
-
Mumbai —
ap-south-1 -
Singapore —
ap-southeast-1 -
US East —
us-east-1
For a website serving users in India, Mumbai (ap-south-1) is usually a sensible choice.
Important: EC2 instances are created inside a specific Region. Make sure you remember which Region you used.
Step 4 — Click "Launch Instance"
On the EC2 dashboard:
Instances → Launch instances
You will now see the Launch an instance page.
This is where you tell AWS what kind of virtual computer you want.
Step 5 — Give Your Instance a Name
Under Name and tags, enter a name.
The name is mainly for your own identification.
Step 6 — Choose an Operating System
Now you need to choose an AMI.
AMI means Amazon Machine Image.
Think of an AMI as:
A ready-made operating system/template for your new server.
You may see options such as:
- Amazon Linux
- Ubuntu
- Windows Server
- Red Hat
- Debian
For learning Linux/AWS
I recommend:
Ubuntu Server LTS
Step 7 — Choose Instance Type
Next you'll see Instance type.
This determines the CPU and RAM available to your virtual server.
For example:
t3.micro
or other current eligible instance types.
For learning and small practice workloads, choose a Free Tier-eligible/low-cost option shown by AWS for your account, rather than assuming a particular instance type is free.
Think of it like buying a computer:
For AWS practice, start small.
Step 8 — Create/Login Using a Key Pair
This is a very important step.
AWS needs a secure way for you to log in to your Linux EC2 server.
Under Key pair, choose:
Create new key pair
Give it a name such as: my-aws-key
Choose:
RSA
For Linux/SSH, download the .pem file.
For example: my-aws-key.pem
Important warning-
Do not lose this file.
Do not upload it publicly to:
- GitHub
- GitLab
- Public websites
Anyone who obtains your private key may potentially be able to authenticate to your server, depending on your security configuration.
Step 9 — Configure Network Settings
AWS will now show Network settings.
You will normally see:
- VPC
- Subnet
- Auto-assign Public IP
- Security Group
For a beginner, AWS's default VPC settings can be used for basic practice.
Public IP-
If you want to connect to your server from your computer over the internet, make sure the instance has a suitable public IPv4 address.
Step 10 — Configure the Security Group
This is one of the most important concepts in EC2.
A Security Group is like a firewall for your EC2 server.
For example:
Internet ↓ Security Group ↓ EC2 Server
You may see options such as:
SSH-
Type: SSH Port: 22
SSH is used to remotely log in to a Linux server.
HTTP-
Type: HTTP Port: 80
HTTP is used when you want people to access your website.
HTTPS-
Type: HTTPS Port: 443
HTTPS is used for secure websites.
For basic Linux practice
You can initially allow:
SSH - Port 22
For a web server, you would typically also allow:
HTTP - Port 80 HTTPS - Port 443
Security recommendation
For SSH, avoid opening port 22 to Anywhere (0.0.0.0/0) unless you have a specific reason.
For learning, you can restrict SSH to My IP when available.
Step 11 — Configure Storage
You will see something like:
This is the disk space of your EC2 server.
For basic practice, the default storage is usually enough.
Think of it like:
Your laptop has a hard disk.
EC2 also needs disk storage.
Step 12 — Review All Settings
Before launching, check:
Step 13 — Launch the Instance
Everything looks good?
Click:
Launch instance
AWS will now create your virtual server.
You should see a message similar to:
Successfully initiated launch of instance
Step 14 — Check Your Instance
Go to:
EC2 → Instances → Instances
You should see your instance.
Initially, the status may be: Pending
After a short time it should become: Running
You can also see:
Instance ID -i-0daef3fed8dcd588bInstance type- t3.microPublic IPv4 address- 13.233.150.88Private IPv4 address- 172.31.3.72Availability Zone- ap-south-1bStatus checks-Initializing >> 3/3 passedStep 15 — Get the Public IP Address
Select your EC2 instance.
Look for:
Public IPv4 address
For example:
13.xxx.xxx.xxxThis is the internet-facing address you can use to
connect to your server, provided the networking/security
configuration allows it
Step 16 — Connect to Your EC2 Server
For Ubuntu/Linux, you can connect using SSH.
On Windows, you can use
- Windows Terminal
- PowerShell
- WSL Ubuntu
- SSH client
Examples-ssh -i my-aws-key.pem ubuntu@YOUR_PUBLIC_IPssh -i my-aws-key.pem ubuntu@13.xxx.xxx.xxxStep 17 — You Are Inside Your AWS Server
If everything works, you will see something similar to:
Congratulations! 🎉ubuntu@ip-172-31-xx-xx:~$You are now controlling a Linux computer running inside AWS.
Try:
pwdThen:
lsThen: