Get Started with Virtual Machines: A Step-by-Step Guide to Setting up an EC2 Instance on AWS.
Tags: aws, virtualmachine, ec2, cloud
Published: 2023-04-08 02:31:06

A virtual machine is a software implementation of a physical machine, allowing multiple operating systems to run on the same physical hardware. In simple terms, A virtual machine is like a computer that exists within another computer. It's a software program that mimics the functions of a physical computer and can run its own operating system and applications independently of the host machine. This means that you can have multiple virtual machines running on the same physical computer, each with its own operating system and software applications. It's like having several computers in one!

## What is EC2?
EC2 which stands for Elastic Compute Cloud  is a web service provided by Amazon Web Services (AWS) that allows users to create and manage virtual machines on the cloud. AWS EC2 provides a scalable, reliable, and secure environment for running virtual machines with various operating systems, such as Linux, Windows, and macOS. EC2 instances can be launched and terminated on demand, allowing customers to scale their infrastructure up or down based on their needs.

In this article, I will guide you through the process of setting up an EC2 instance on AWS.


**Step 1: Create an AWS Account**

The first step to setting up an EC2 instance on AWS is to create an AWS account. To do this, go to the [AWS website](https://aws.amazon.com/free/?trk=2d3e6bee-b4a1-42e0-8600-6f2bb4fcb10c&sc_channel=ps&ef_id=Cj0KCQjw_r6hBhDdARIsAMIDhV8AzSIsMcAfttmLhUti3VIx8SbZmUJI4WWJvEdzzbZbepZ87ktBnQMaAoOJEALw_wcB:G:s&s_kwcid=AL!4422!3!645125273261!e!!g!!aws!19574556887!145779846712&all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all) and click on the "Create a Free Account" button. Follow the prompts to create your account.

Once your account is created, log in to the AWS console. This is where you will manage all of your AWS resources, including EC2 instances.


**Step 2: Launch an EC2 Instance**

To launch an EC2 instance, follow these steps. 

**1. Type EC2 in global search box, then select EC2 from the options.** 
![EC2 Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tlquk5yuh2cimsrmrij.PNG)

---


**2. On the the EC2 dashboard, click on instances then the "Launch Instance" button.** 

You will be presented with a variety of options for configuring your instance.

![EC2 Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zemprj98k2sggkij92ks.jpg)

---

**3. Name your Instance and add Tags.**

Give your EC2 instance a name. You can also add tags to your instance to help you organize and identify it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qspgec8rsiki9fm0a2kd.png)

---

**4. Choose an Amazon Machine Image (AMI)**

An Amazon Machine Image (AMI) is a pre-configured virtual machine image that includes the operating system, application server, and any other software required to run your application. You can choose from a variety of pre-configured AMIs provided by AWS, or you can create your own custom AMI.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqquicibb4joh5oqjnba.PNG)

---

**5. Choose an Instance Type**

The next step is to choose an instance type. An instance type defines the CPU, memory, storage, and network capacity of your EC2 instance. You can choose from a variety of instance types depending on your specific requirements.

- A t2.micro instance which is selected by default, has 1 vCPU and 1 GiB Memory. The t2.micro instance type is eligible for the free tier. In Regions where t2.micro is unavailable, you can use a t3.micro instance under the free tier.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcinqq79peqsh7akn17t.PNG)
Then choose an existing key-pair, or create a new one

> _**It is not recommended to proceed without a key-pair as it is needed to connect to your instance. If you launch an instance without a key pair, then you can't connect to it.**_
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zza7uws01gqa3x342x2.PNG)

---

**6. Configure Instance Details: (Network Settings, Security Group)**

A security group is a set of firewall rules that control the traffic that can access your EC2 instance. You can configure your security group to allow traffic from specific IP addresses or ranges, or to allow traffic from anywhere.

>

-  Add SSH(port-22) and HTTP(port-80) rules in Inbound security groups rules to access your instance from putty(ssh) and through web browser(internet) respectively._
-  _ Keep the default selections for the other configuration settings.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vryvcixn6xnzgcypw861.PNG)

---

**7. Add Storage.**

You can add storage volumes to your instance. AWS offers different types of storage, such as Elastic Block Store (EBS) and Instance Store.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ba3v3o1bej7secspqer3.PNG)

---

> **OPTIONAL: Advanced Details**
> In this section, everything can be left as default. You can also configure it. You can pass user data to the instance that can be used to perform automated tasks and even run scripts after the instance starts.

**8. Review and Launch Your Instance**

Once you have satisfied with your instance settings, you can launch your instance.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcioz345rmvjnu112qnj.PNG)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng5prdorkng4e9jtc38c.PNG)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w32uxtdgxxcm0x5otv5r.PNG)


**Step 3: Connect to Your Instance**
There are multiple ways to connect to your instance. After your instance is launched, you can connect to it directly using EC2 instance connect, remote desktop protocol (RDP) client or a secure shell (SSH) client. To do this, you will need to use the key pair that you created earlier.
Amazon EC2 Instance Connect provides a simple and secure way to connect to your EC2 instance using a browser-based client. To connect to your instance,

- Go to the [EC2 console](https://us-east-1.console.aws.amazon.com/ec2/home?region=us-east-1#)
- In the navigation pane, click on Instances 
- Select your instance and click the "Connect" button. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eyjj01ind0rau98wqiqh.jpg)
- Enter the custom username (ubuntu in this case) and click on connect.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fd1ep5noa020g64bqvq9.PNG)
_And that's it! Your EC2 instance is up and running!_
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7980tstugqhfk252k1w.PNG)

 
Once you are connected to your EC2 instance, you can install and configure your application. This may include installing any necessary software, configuring your web server, and setting up any databases or other dependencies.


Setting up an EC2 instance on AWS as a beginner can seem daunting at first, but with the right guidance, it can be a straightforward process. By following the steps outlined in this article, you can quickly set up an EC2 instance and start running your applications in the cloud.