EC2 Create a server
Welcome to the AWS practice lab for creating a new server! In this article we will go ahead and create an EC2 server so that we can run our web application on it.
Alright, let’s get started! Click on EC2 under services.
As we can see we don’t have any instances running. Instances are basically the servers we create. Click on Running Instances, or click on Instances on the sidebar.
Click on Launch Instance to create a new EC2 Server.
Here you can see that AWS has conveniently listed some Amazon Machine Images (AMIs) for us. There are a bunch of them. They are simply templates that let us startup servers for common use cases. You can also check on Free tier only to see options available on free tier.
You can choose whichever you like/prefer. I am going to go ahead with Amazon Linux AMI from free tier options
You will now be prompted to choose an instance type. An instance type simply defines the server configuration like processing power, RAM, storage, etc. You get a few different options and again, a free tier option is available, which is what I am going to choose. This instance provides 1 CPU (Virtual), 1 Gig of RAM and EBS Storage, the details of which we’ll see ahead.
Cool, now there are two options we have, Review & Launch and Next: Configure Instance Details. For the purposes of this guide, lets choose Configure. Here we can configure our instance details.
You can launch multiple instances at a time as well. Also, if you wish to set up auto scaling, you can set up an auto scaling configuration from here (if you add multiple instances of course). You may also have noticed that we can check Request Spot instance as well, which will significantly reduce the cost of our servers (if not in free tier).
The instance will be a part of a VPC, hence making it available throughout that VPC.
If you scroll down, you can also choose the behaviour on shut down, whether you want to stop (keep but shut down) or terminate (remove instance or delete forever). Apart from that, what you see here is that you can choose to have a dedicated instance, that is literally a physical server of your own, managed by AWS! You may also use Cloud Watch to monitor your servers.
Lets click next to add storage.
Here you can choose the size for your storage along with the Volume Type. You can ofcourse add more volumes as well. More details about Volume type in EBS section of this blog. I’m going to go ahead with the defaults.
You can then add tags if you like, I’ll skip this step. Tags are basically useful when you want to perform some actions collectively on a set of services, like perform an action on multiple EBS volumes with the same tag.
You can now configure a security group. Now there’s nothing to fear here. It’s simply a set of rules that define what kind of requests can come in and what can go out. E.g. If you want to manage your server through SSH from your system (which you obviously would want to), you can enable requests on TCP port 22 in your inbound settings. However, never keep it on 0.0.0.0/0. This means that anyone who gets your server’s IP address can access your server, and trust me hackers can very easily find random IPs. You may keep it like that for practice but not in production. Probably not a good idea even in test/staging servers.
Now Press Review and Launch. Here you’ll be able to see all the details of your instance. The selected AMI, instance type, security groups, instance details and storage.
If you press on Launch, you’ll be presented with the following screen. To be able to SSH to the instance, you need to have a valid key pair. The key pair is used to authenticate the user and if the user is authorized, they get access. Since we haven’t created a key pair yet, none are found. Lets create one.
Select Create new key pair and enter a name for it. I just named it ec2-practice and then clicked Download key pair.
Store this keypair securely and do not lose it. It is your key (no pun intended) to your server.
You can now click Launch Instances to, well, launch your instances. Your instances are launching.
You can check the status of your instances by going to Services > EC2 > Instances. Here it says that the server is initializing. Give it a few minutes and it’ll be up.
In the table you can see the Instance ID, type, availability zone (zone inside a region), state, key name, launch time, security groups, etc.
A few minutes later, you should see the status checks having a check ✅. This means that your instance is now live! You can now access it via SSH. You can click on connect to view SSH details.
Here you can see the URI of the AWS server, along with an example SSH string you can copy paste to access your server. Let’s go ahead and paste the same in our terminal. If you are a windows user, you can use PuTTY, a free ssh client for windows.
Make sure you are in the folder where your key was downloaded (1). Paste the ssh string here and if this is the first time you ssh into this particular instance, if will ask you to confirm to trust this server. Go ahead and type yes to continue (2).
You will need to update the permissions for your key file on your system. To do so, type:
chmod 400 ec2-practice.pem
Retry the ssh connection string. You will then be connected to the console of your instance. 🎉
Thank you for reading this article! 👋