How to Setup an EC2 Instance on AWS
Alright so before we open up our toolbox and start setting us up an EC2 Instance on AWS, let's first discuss what an EC2 instance really is. Some of you might already be aware of this, however, I have a feeling that most of you who are just starting to get their feets wet in the International waters of AWS might still not be too sure about what it is that EC2 does and why we use it?
So, first let's tackle that basic but very important question. Let's discuss what AWS EC2 Instance is and what it does for us, but in a language that's more suited for humans and not for AWS overlords. đ
What is an AWS EC2 Instance?
An EC2 instance is just fancy name for a virtual machine on Amazon Servers. Whatâs a virtual machine, you ask, well thatâs the actual question here.
Alright, so letâs imagine you are amazon, and youâve this vast amount of IT Infrastructure (like CPU, RAM, Hard Disk etc) with you. However, itâs not always that you use 100% of it. Actually it might be fair to say that you will never use 100% of this and being one of the worldâs most profitable and wealthy organisations you just invested in these resources for redundancy and backup purposes. But because of that for now they are just being wasted and not being used in any financially sensible manner.
So, you get an đĄ idea! To understand this idea, let's first talk a little bit about renting commercial real estate and a very specific type of office workspace nowadays known as co-working spaces.
Renting in real estate is obviously a very common idea. Not all businesses and people can afford to rent out a separate physical office space or a building to accommodate their teams and work. Due to this, nowadays, co-working spaces are so much in demand. They give a chance to small entrepreneurs & businesses to operate in a similar fashion as that of their big counterparts. However, if you think about it, most co-working spaces are not separate spaces. They are logical division of a common space which is shared by different businesses and individuals while giving them a perception of private work space.
This is exactly what our idea was based on. What if you can rent all this IT infrastructure out to people and businesses who canât afford to buy their own separate servers. Now because obviously people canât rent the entire server most of the times, because itâs still pretty expensive and most of the time they donât even require that much resources, you will need to divide it somehow (Although, not physically, as remember you canât break the hardware to divide it, that will just make it useless đ). So this is where the concept of Virtual Machine & Cloud comes. Virtual machines allows you to create separate logical divisions with your IT infrastructure which gives the perception of private server space to the user but is actually just a piece of the common hardware thatâs being also used by other users.
Hopefully, this gives you a better sense of what EC2 instances in AWS are all about. Now, letâs see how to setup one. I will lay this down in a step-by-step approach and will display screenshots alongside so that it's easier for you to follow.
Step 1. Open âAWS Consoleâ by visiting âhttps://console.aws.amazon.comâ.
Step 2. Navigate to âEC2â service in âComputeâ service provided by AWS.
Step 3. Create a new EC2 machine by clicking on âLaunch Instanceâ at top right. This will open up a launch wizard which will have several steps in order to configure the EC2 machine.
Step 4. At the first step of wizard, you need to select the OS for your EC2 machine. In our case, we are going to select Ubuntu 20.04 LTS. Just search for âUbuntuâ in the search box and select the version 20.04.
Step 5. After that, we are asked to select the instance type. The type of instance is critical to cost or bill of the ec2 machine. Obviously, the more powerful the configuration, the more the cost. Just select what you think suits your case the best. In our case, for now, for prototyping even t2.micro or t2.small is fine. However, for working with more data we will need to increase the capacity eventually, also add GPU support. However, donât worry, all this can be done after we create the instance. Thatâs the beauty of cloud you can up scale and down scale at any time you want.
Step 6. Now once weâve selected the instance type, we need to configure our instance, You can just move to the next step at this stage without changing any of the default settings.
Step 7. In this step, you can alter the amount of storage or hard drive space you want to be associated with your ec2 instance. By default itâs 8 GB of SSD which is sufficient for now. In case you want to alter it, you can do that after the creation of the instance.
Step 8. This step will allow you to associate Key-value pair based tags to the instance for future reference and filtering. Not at all mandatory and you can skip this step to move to the next stage.
Step 9. Alright, so this is something that we need to talk about. At this stage you can manage and edit security groups and access rules to the instance.
Security groups manage access to the instance that you are creating.
Any server or virtual machine can be accessed by various ports through various protocols like tcp protocol or ssh protocol etc. However, this access needs to be specified and it gets specified at this step.
By default, only ssh protocol is open at port 22. This provides you access to the instance through remote ssh connection from any computer if you have the credentials and the ip address of this instance (will talk about this in a minute).
However, you can also add more protocols and ports for increased access to the instance. For example, if you want people to access your website that you are going to deploy on your ec2 instance, then in that case you will most probably want to allow access using http protocol on port 8080. This completely depends on your requirements.
In our case, we can just leave it as is. We only want the ssh access to our instance.
Step 10. Alright, so now that you are done with most of the configuration, the launch wizard is going to show a popup which will ask you to create a ssh key pair. This and the next step are very crucial.
From the dropdown select âCreate a new pairâ option.
Step 11. Once the option is selected, select RSA as key pair type and enter any name for the ssh key. Once done, Press the âDownload Key Pairâ button. This will download the key to your local system.
This ssh key is the only way to access this instance and if you lose it, you wonât be able to access the ec2 instance. So you need to store it safely and confidentially.
Once done, you can press âLaunch instancesâ button at the bottom of the popup.
Step 12. Once the instance is created, it will show up in the instances list at the EC2 dashboard area. To start the instance, just select the instance and then go to âInstance stateâ and select âStart instanceâ.
NOTE: Remember, you are ONLY BILLED when the Instance is in the RUNNING state. Make sure, when you are not using the instance, itâs in the STOPPED state.