AWS - Creating and Connecting to your first Virtual Machine using EC2


How to Create an EC2 instance / Virtual Machine with an Ubuntu AMI on AWS: A Step-by-Step Beginner’s Guide
If you’re new to cloud computing and want to learn how to create a virtual machine (VM) running Ubuntu Linux on AWS, this tutorial is for you. We’ll cover everything from basic concepts to launching your VM and connecting to it securely.
What is Virtual Machine?
A virtual machine is like a small computer inside your real computer. It works just like a normal computer, but it’s made with software. You can use it to run different programs or even different operating systems, like Windows or Linux, without changing your real computer. It helps keep things separate and safe. For example, if something goes wrong in the virtual machine, your real computer won’t be affected.
What is Ubuntu?
Ubuntu is a popular Linux operating system known for its ease of use, stability, and community support. Ubuntu Server is a version optimized to run on servers and cloud environments.
What is AWS EC2?
Amazon EC2 (Elastic Compute Cloud) is a web service that provides resizable compute capacity (virtual servers) in the cloud. Instead of buying physical servers, you rent virtual machines called instances on demand.
Think of EC2 as renting a computer in the cloud that you can configure, run software on, and control remotely.
Prerequisites Before We Start
- An AWS account. If you don’t have one, you can create it for free here.
Let’s Get started now that we have an account and understanding of basic terms.
Log in to the AWS Management Console
Click here to login as Root User.
Log in with your AWS credentials.
Note : You should use IAM user to login and create or use any resource on AWS , We will learn more about IAM in the upcoming sessions. Currently login as Root User.
Open the EC2 Dashboard and follow the below steps
Use the search bar at the top and type EC2.
Click on EC2 from the results to open the EC2 Dashboard.
Ensure you have selected the AWS region closest to your location.
Click on the Launch instance button as shown below.
Launch an instance wizard will open, Type the Name as "My First EC2 Instance"
Scroll to the "Amazon Machine Image" section, choose the "Ubuntu Server 24.04 LTS" Operating System image and select an AMI Eligible under Free tier.
Scroll to the Instances type section and select t2.micro instance type, which qualifies for the free tier.
The t2.micro instance on AWS offers a cost-effective solution for general computing tasks, providing moderate CPU performance suitable for various workloads.
Scroll to the Key pair (login) section and click on the "Create a new key pair" option to generate a new keypair.
The Key pair creation wizard will open, Type your key pair name as "EC2 Default KP". Choose RSA as the key pair type and select the .pem as private key file format.
Click on the Create key pair button and download the private key pair
Note: Don't forget to securely store the downloaded key pair since it's essential for SSH access to the EC2 instance
What is a Keypair in AWS?
In AWS, a key pair is like a special password made of two parts—a public key and a private key. You use this key pair to safely connect to your Virtual servers / Virtual Machine (called instances). The public key stays with the server, and you keep the private key with you. Together, they help make sure only you can access your server.
Scroll down to Network Settings . Select Create Security Group and Allow SSH , HTTPS and HTTP traffic. Select the option Anywhere 0.0.0.0/0 as shown below.
In AWS, a Security Group acts like a virtual Firewall . It is like a gate that controls what kind of traffic can go in and out of your server.
Scroll down to Configure Storage. Here you can select the Volume size and type for your Virtual Machine.
What is Root Volume ?
In AWS, the root volume is the main storage of a virtual server (EC2 instance). It holds the operating system and important files needed to start and run the server—just like the main hard drive on your computer.
Review your settings and click on Launch instance button.
If you want to create more than 1 Virtual machine of same settings at once you can specify the number of instances . Here we are creating only 1 VM so number of instances = 1 .
The instance launch will be successfully initiated. Click on Instances as shown below.
You will navigate to Instance Dashboard where you can see the instance or Virtual machine is in Running State. Select My First Instance and click on Connect button.
Connect to instance wizard will open
Choose the EC2 Instance Connect option to connect directly from the AWS Console.
Click on the Connect button to connect to the instance using the EC2 Instance Connect option provided by AWS
You will be successfully connected to your EC2 Instance
Type "whoami" command in the terminal to view your username
You can alternatively select SSH Client for connecting to your Linux instance.
which will be discussed latter.
Now practice some commands and installations etc.
Once you have finished practicing don’t forget to terminate your EC2 VM.
Click on the Instance State button from the top right of the page to either Stop, Reboot or Terminate the running instance. We terminate the instance as of now.
After clicking on Terminate instance in the above step you will navigate here , Click on Terminate(delete) button as shown below.
Wait for the instance to terminate.
Congratulations on completing this lab and Creating Your First EC2 Instance on AWS! Good job! Follow for more detailed blogs like this.
Extra :-
EC2 instance actions (stop, start, reboot, hibernate, terminate) and what they do:
Stop
What it does: Shuts down the instance like turning off a computer.
You can start it again later.
Billing: You stop paying for compute (CPU), but storage (EBS) still costs money.
Start
What it does: Turns the instance back on after it was stopped.
Like powering on a computer.
Reboot
What it does: Restarts the instance (just like clicking “Restart” on your PC).
No data is lost, and it happens quickly.
Useful for updates or fixing small issues.
Hibernate
What it does: Saves what's in memory (RAM) and stops the instance.
When you start it again, it picks up where it left off.
Like putting a laptop to sleep.
Note: Not all instance types support hibernation.
Terminate
What it does: Deletes the instance permanently.
All data on the instance is lost (unless you backed it up).
You can’t start it again.
Subscribe to my newsletter
Read articles from Iqbal Shaikh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
