How to create and set up your first AWS EC2 Instance
Tags: aws, cloudcomputing, devops, backenddevelopment
Published: 2023-08-17 21:24:21

## What exactly is an AWS EC2 Instance?
Amazon Elastic Compute Cloud (AWS EC2) is an Infrastructure as a service (IAAS) cloud service provided by Amazon.com that enables users rent a virtual machine where they host and run their computer applications. Amazon EC2 provides users with what is called an Instance, a web service through which a user can boot an Amazon Machine Image (AMI) to configure a virtual machine that contains your software. Users can create, launch or terminate EC2 instances as desired. Websites such as Netflix (As at 2022, they were the biggest EC2 user by monthly spend), Facebook, LinkedIn and Twitch are some of the most popular websites that use AWS EC2 for their cloud services.

Get ready to get your steps in as i walk you through how to create and configure your first EC2 Instance.

## Create an AWS EC2 Instance
To be able to create an EC2 Instance, you need to have an AWS account, if you need guidance creating one you can check out [how to create an AWS account](https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-creating.html). Once you have an AWS account, you can go ahead and begin creating your EC2 Instance. 

First, when you are logged into your AWS account, you go to EC2 instances view, this can be done by using the search bar to navigate to EC2 instances by clicking on EC2 and then navigating to the Instances view

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

Where you can create (launch) and manage your EC2 Instances. To begin creating your new Instance, click on the Launch Instance button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yq3mmejd40k9t1r53me2.png)
This should take you to a view with a form that allows you configure your EC2 Instance. I will walk you through basic configuration in **6** steps: 

**Step 1:** Choose a name for your EC2 Instance. You can choose whatever name you want for your Instance. E.g. myinstance-1

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

**Step 2:** Select the Amazon Machine Image (operating system) you will prefer to use to launch your Instance.

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

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

As a beginner or a non-enterprise user, it is advisable to select an Amazon Machine Image (AMI) that is free tier eligible to keep cost at a minimum.

**Step 3:** Select the Instance type that’s most suitable for your use case. Amazon EC2 provides a wide array of Instance types that suit different use cases. These Instance types have various combinations of storage, CPU, memory and networking capacity. To learn more about how different Instance types can meet your computing needs, check out [AWS EC2 Instance types](https://aws.amazon.com/ec2/instance-types/). Again, it is advisable to select an Instance type that is low cost or free tier eligible if you are not an enterprise user.


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

**Step 4:** Create a key pair or select one if you have previously created one. Your key pair consists of a public key and private key. They serve as your security credentials that allow you access to your EC2 Instance. Go to [Amazon EC2 key pairs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) to learn more about key pairs.

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


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

**Step 5:** Configure your network settings. The default network settings are fine the way they are but you can edit them to configure them as you’d want especially to select a particular availability zone.


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


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

Availability zones are isolated and independent data centers spread across a region that offers protection from failures or catastrophic events in data centers at other zones. Although the default no preference setting (which is preferred setting) allows access to any availability zone but you can select a specific availability zone of your choice.

**Step 5.5:** The second half of the network settings require you to select or create a security group. A security group basically acts as a virtual firewall that controls inbound and outbound traffic to your Instance and by extension your website or web app. You can instantly create and configure a security group from the edit network settings view.


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

First, you choose a security group name, note that you will not be able edit this name once you have created the security group and your security group name cannot start with `sg-`. A security group name must also be unique for the [VPC](https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html). After entering your security group name, you can enter a brief description of your security group (between you and me that could be anything). Now it gets interesting, you will configure your Inbound security group rules. The default security group rule listens on port 22 which allows SSH access for Linux Instances or RDP access for windows Instances from command line on your computer. 

I will now walk you through how to create a new Inbound security group rule if your instance is going to function as a web server. First, you click on the “Add security group rule” located after the default security group rule then you get another security group rule that looks like the second image below. 

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

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

We are going to be creating two new security group rules that allow all IP addresses access your instance via HTTP and HTTPS so your users can browse content on your web server.
For the first security group rule, select `HTTP` as `Type` which refers to network traffic type, this will automatically set `Protocol` to `TCP` and `Port range` to `80` as that is the port number assigned to HTTP server. You will then select `Source type` which refers to where your instance can be accessed from. You can either allow your instance to be accessed from anywhere or only from predefined known sources i.e. setting `Source type` to `My IP` which specifies your current IP address as the only source that can access your Instance or to `Custom` where you can specify the IP Address or security group that will be allowed access to your Instance. So for the purpose of this post, you will set our `Source type` to `Anywhere` which will set the `Source` to `0.0.0.0/0` this allows your Instance to be accessed from anywhere in the world via HTTP.

Configuring the second security group rule should be straightforward, you will set the `Type` to `HTTPS`, this will also automatically set `Protocol` to `TCP` and `Port range` to ‘443’ this is because similarly, ‘443’ is the port number assigned to HTTPS which is a secure version of HTTP. Just like the HTTP rule, we will also set `Source type` to `Anywhere`. When you are done, your Inbound security group rules should look something like this;

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

You can learn more about security groups by checking out [Security groups](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html).

**Step 6:** Configure storage. When it comes to configuring storage options for your EC2 Instance, it is okay to go with the default option which is quite sufficient if your software does not require enormous storage space. AWS offers free tier eligible customers up to 30GB of storage space (EBS General Purpose (SSD) or Magnetic Storage)

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

And that seems like a sufficient amount of storage space so I will stick with the default storage options.
At this point, we do not need to change any of the advanced details so we will leave them and then proceed to launch our EC2 instance by clicking the orange button highlighted in the image below

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

Once you click the button, the Instance launch process will be initiated and in a few seconds your EC2 Instance will be created. This will then take you to a view that shows that the launch of your instance is successful.

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

Then click the ‘View all Instances’ button at the end of the page to view and manage all the Instances you have created.
 
Ensure that your Instance state shows as running and that it passes 2/2 status checks, if this isn’t the case, you may need to refresh this web page for the changes to reflect.

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

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

At last, your AWS EC2 Instance is up and running, you can now proceed to deploy your software to your virtual server and put your website or web app on the streets of the internet. In another post, I will talk about how to deploy your code to your EC2 Instance, till then stay tuned! Cheers guys.