AWS Builder Center
Amazon EC2 Explained: From Launching Your First Instance to Running an Application

Amazon EC2 Explained: From Launching Your First Instance to Running an Application

Learn how Amazon EC2 works, what happens behind the scenes when you launch an instance, and how to connect, configure, secure, monitor and manage your own virtual server on AWS.

Amazon EC2 Explained: From Launching Your First Instance to Running an Application
Introduction
When I first started learning AWS, one of the services I wanted to understand was Amazon EC2. I kept hearing that EC2 is used to host websites, run applications and manage servers in the cloud.
But how does it actually work?
Let's understand it step by step, starting with a simple example.
Imagine you want to host a website. Normally, you would need a physical computer, an operating system, storage, internet connectivity and other resources. You would also need to maintain that machine.
Amazon EC2 makes this easier by allowing you to rent a virtual server in the AWS Cloud instead of purchasing a physical server.
1. What is Amazon EC2?
Amazon EC2 stands for Amazon Elastic Compute Cloud.
It is a service provided by AWS that allows us to create and use virtual servers called instances.
With an EC2 instance, we can:
- Run websites and web applications. - Host backend servers. - Store and process application data. - Run development and testing environments. - Perform computing tasks.
The important point is that we can select the computing resources we need and manage our server whenever required.
2. How does an EC2 instance work?
Let's take a simple example.
Suppose you want to host a website. You need a server that can receive requests from users and send back the website.
Here is what happens:
1. You create an EC2 instance using the AWS Management Console. 2. AWS allocates computing resources on its infrastructure. 3. The selected operating system starts on your virtual server. 4. You connect to the instance remotely. 5. You install the required software and application. 6. Users access your application through its network address.
That's the basic working process.
Remember: EC2 is not a physical computer sitting in your room. It is a virtual server running on AWS infrastructure.
3. Important components of an EC2 instance
Before launching an instance, we should understand a few important terms.
1. AMI (Amazon Machine Image)
An AMI is a template used to launch an EC2 instance. It contains the operating system and can include additional software.
Examples:
- Amazon Linux - Ubuntu - Windows Server
Think of an AMI as the starting blueprint for your server.
2. Instance Type
An instance type decides the computing resources available to your virtual server.
It includes:
- CPU - RAM - Network performance - Storage capabilities
For example, a small application may need fewer resources, while a high-traffic application may need more computing power.
3. Key Pair
A key pair is used to securely connect to an EC2 instance.
It contains:
- Public key – AWS places this on the instance. - Private key – You keep this securely.
For Linux instances, SSH can use the private key to authenticate your connection.
Never share your private key with anyone.
4. Security Group
A security group acts like a virtual firewall.
It controls which network traffic is allowed to reach your instance and which traffic is allowed to leave it.
For example:
- Port 22 – SSH connection. - Port 80 – HTTP website traffic. - Port 443 – HTTPS secure website traffic.
5. EBS (Elastic Block Store)
EBS provides persistent block storage for EC2 instances.
Think of it as the hard disk of your virtual computer.
It stores operating system files, application files and other data.
6. VPC (Virtual Private Cloud)
A VPC is your logically isolated network in AWS.
Your EC2 instance is launched inside a VPC and a subnet. These networking settings help determine how the instance communicates with other resources and the internet.
4. How to launch your first EC2 instance
Now let's understand the actual process.
Step 1: Open AWS Management Console
Log in to your AWS account and search for EC2 in the services section.
Open the EC2 dashboard and select Launch instance.
Step 2: Give your instance a name
Enter a name that helps you identify your server.
For example: "My-First-EC2-Server"
Step 3: Select an AMI
Choose the operating system you want.
For beginners, Ubuntu or Amazon Linux is a good starting point.
Step 4: Choose an instance type
Select an instance type according to your application's requirements.
For learning purposes, choose an eligible small instance after checking the current pricing and account offers.
Step 5: Create or select a key pair
Create a new key pair and download the private key file.
Keep it safe. You will need it when connecting through SSH.
Step 6: Configure network settings
Select your VPC and subnet.
Configure the security group. If you want to connect through SSH, allow TCP port 22 only from your own IP address whenever possible.
Step 7: Configure storage
Choose the required EBS volume size.
For a basic learning server, the default storage configuration may be sufficient.
Step 8: Launch the instance
Review your configuration and click Launch instance.
AWS starts creating your virtual server.
After a short time, its state changes to Running.
Congratulations! Your first EC2 instance is ready.
5. What happens behind the scenes when we launch EC2?
This is the interesting part.
When you click Launch instance, AWS does much more than simply create a server.
Here is the simplified sequence:
1. AWS receives your launch request. 2. AWS checks your configuration and permissions. 3. It allocates suitable computing capacity. 4. It prepares the instance using the selected AMI. 5. It attaches the required storage. 6. It configures networking and security settings. 7. The operating system starts booting. 8. AWS performs instance status checks.
Once the instance becomes available and passes its checks, you can connect to it.
In simple words, AWS handles the underlying physical infrastructure while you manage your virtual server.
6. How do we connect to an EC2 instance?
Launching an instance is only the beginning. We also need to access it.
For a Linux instance, one common method is SSH (Secure Shell).
SSH allows us to remotely access the Linux terminal from our own computer.
A typical command looks like this:
"ssh -i my-key.pem ubuntu@YOUR_PUBLIC_IP"
Here:
- "ssh" starts a secure connection. - "-i" specifies your private key file. - "my-key.pem" is your downloaded private key. - "ubuntu" is the login username for the Ubuntu AMI. - "YOUR_PUBLIC_IP" is your instance's public IP address.
Once connected, you can execute Linux commands just like you would on a normal computer.
For example:
"sudo apt update"
This updates the package information on Ubuntu.
You can also connect using EC2 Instance Connect through the AWS Console, when the instance meets its requirements.
7. How do we host a website using EC2?
Let's take our learning one step further.
Suppose we want to host a simple website on our EC2 instance.
After connecting to an Ubuntu instance, we can install a web server such as Apache.
Run:
"sudo apt update"
"sudo apt install apache2 -y"
Start the Apache service:
"sudo systemctl start apache2"
Enable it to start automatically when the system boots:
"sudo systemctl enable apache2"
Now make sure your EC2 security group allows inbound HTTP traffic on port 80.
Open your browser and enter:
If everything is configured correctly, you should see the Apache default web page.
That's it! Your website is now being served from an EC2 instance.
This is a simple example of how cloud computing works in a real-world application.
8. What happens when we stop or terminate an instance?
EC2 instances have different lifecycle states.
Running: Your virtual server is operating and can process requests.
Stopped: The instance is shut down. You can start it again later. EBS storage generally remains available.
Rebooting: The operating system restarts.
Terminated: The instance is permanently deleted and cannot be restarted.
One important thing to understand is that stopping and terminating are not the same.
Stopping an instance is similar to shutting down your computer. Terminating an instance is similar to deleting that virtual machine.
Always check your storage and deletion settings before terminating an instance.
9. How does AWS charge for EC2?
EC2 follows a pay-as-you-go model, but the final cost depends on the resources and options you use.
Some important billing factors include:
- Instance type and running duration. - EBS storage. - Data transfer. - Public IPv4 address usage, where applicable. - Additional AWS services.
AWS offers different purchasing options, such as On-Demand, Savings Plans and Spot Instances.
For beginners, the most important thing is to understand that a running instance can incur charges even when you are not actively using it.
Before launching an instance, check the current AWS pricing and Free Tier or credit eligibility for your account.
After practising, stop or terminate resources that you no longer need.
10. Where are EC2 instances used in real life?
EC2 is used in many practical applications.
Web Hosting: Running websites and web applications.
Application Servers: Hosting backend applications and APIs.
Development and Testing: Creating temporary environments for developers.
Data Processing: Running workloads that require computing resources.
Machine Learning: Running suitable computing workloads, including GPU-based workloads with supported instance types.
Business Applications: Hosting enterprise software and internal applications.
Conclusion
Amazon EC2 is one of the fundamental services to understand when learning AWS.
The best way to learn it is not just by reading about it but by actually launching an instance, connecting to it, installing software and understanding how everything works together.
Start with a small Linux instance, experiment with it and learn each component step by step.
Once you understand EC2, many other AWS services become easier to learn because you already understand the basics of cloud-based computing.
My takeaway: EC2 is essentially a virtual computer in the cloud, but understanding how it is created, connected, secured and managed is what makes cloud computing interesting.
Happy learning! 🚀
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article