A Guide to spinning up an EC2 Instance
What is an EC2 Instance?
An EC2(Elastic Compute Cloud) instance is a server hosted on AWS(Amazon Web Services). In simpler terms, these are virtual machines which are running on a cloud. EC2 instances allow you to choose from CPU, memory, storage and networking configurations based on your requirements. They are scalable, reliable and accessible globally, which means if you needed to host your own cloud based applications, you will be able to access it from any region(unless you specify). The pricing for these instances is based on pay-as-you-go model, meaning you only need to pay for the resources that you have used. You don’t need to pay an upfront fee before using these instances.
Why do you need it?
You can use an EC2 instance for:
Hosting your web applications / database.
Extra storage and memory.
High Compute Requirement (eg. training a ML model).
and Many more.
Prerequisite
To get started, you will need an AWS account. If you don’t have one you can quickly create an AWS free-tier account by visiting: aws.amazon.com/free
Let’s Spin it up
Okay! so once you have your AWS account ready, we can go ahead and create an EC2 instance. Follow the steps given below:
Navigating through…
Go to your AWS console page. It should look similar to the image given below:

Click on the menu/hamburger (☰) icon in the top left corner of the page and select “All Services“ option. Once you are on the All Services page you should see a list of services offered by AWS.
The services are listed by the categories. We can find the EC2 service under the Compute Category. Click on the EC2 option(highlighted in the image below) available under the Compute Category.

Once you click on the option, you should be able to see an overview page which lists the benefits and features of EC2 service.

Click on the Dashboard option given in the left sidebar. Then click on the Launch instance button displayed under the section by same name.

You should be able to see this page:

Creating an Instance
First, we will name our instance. I will be naming it “my-first-instance“. You can also choose to add tags to it.

Next step is selecting Operating System that we want to use inside our instance. Under the Application and OS Images section, we can see that there are a lot of options that EC2 offers. We can choose from different Linux distros, Windows or Mac Os. For this tutorial we will choose Ubuntu.

We also have the ability to select a different version and architecture of our selected OS. But for this tutorial I am keeping the default options.
Now its time to select an instance type, which is selecting a hardware configuration for our EC2 instance. You are free to choose from any of the available instance types. For the tutorial purpose, I will be selecting t3.micro (or t2.micro,based on your region it might change) as it is also available under free tier.

Now we need to setup login. We will be using SSH to login to our EC2 instance. For that we need to provide a key-pair name. If you are creating an instance for the first time, you will need to create it first.
To create a key-pair, click on “Create new key pair“ option. A dialog box will appear. In that, enter a name for the key pair, select the type of key-pair as RSA and private key format to .pem. Then click on “Create key pair“.

Once you have done the above step, a file with the format .pem will be downloaded to your PC.
As for Network and configuration settings, we can leave them to the default setting provided by AWS.
You can view your selections in the Summary section in the right side of the screen. Once you have confirmed your selections, click on Launch Instance button. It will take a few seconds to create the instance. Once the instance is created you should be able to see the following output:

You can also view the instance in the Instances page.

Accessing the instance
To access our instance from your PC, we will require the .pem file that was downloaded in the earlier steps. And the Public IP of the instance that you created.
To get the Public IP, click on the name of your instance, you will be able to see the detailed information about your instance. In there, locate the Public IPv4 address and copy it.

I will be using WSL2 with Ubuntu Distro for performing the upcoming steps.
First we need to move .pem file to a secure location. Run this command:
mv /current/path/.pem ~/.ssh/then runchmod 400 ~/.ssh/<name of your .pem file>.To login to your EC2 instance from your terminal, you will need to run the following command:
ssh -i ~/.ssh/<name of your .pem file> ubuntu@<copied Public IP address>.Once you are logged in, you will be able to see a welcome message.
Thats it! Now, you can try out linux commands or do anything you want.
Remember to delete the instance via the AWS console once you are done using it. EC2 instances charge you based on runtime, so as long as the instance is running you will incur cost even if you are not actively using the instance.
What Next?
Explore the Network and configuration settings.
Explore different instance types.
Try hosting a web application on the instance.
Thanks for reading! Happy Learning!
