Are you trying to launch an EC2 instance in AWS but it’s too confusing?
This post will show you step by step how to do it.
What is an EC2 instance?
The instances that AWS provides are basically servers that users can configure through the internet, in a matter of minutes. The instances are very flexible in terms of configuration, AWS allowing you to choose in what Availability Zone the instance should be launched and more. When launching the instance, you will be asked to create a key pair. The Key Pair will allow you to securely connect to your instance.
How to lunch an instance?
1. Go to the EC2 Dashboard
You can do that by clicking the services menu: Services->EC2
As you can see from the picture above, I already have an instance (server) running. That instance is actually hosting this blog.
2. Click on Launch Instance
Now you have to choose what type of server you would like to launch. There’s plenty to choose from. Choose the one that you are most comfortable with and meets your needs. For this example I will select the Amazon Linux AMI, the first one in the list. It’s the one that AWS provides and it comes with a bunch of stuff already installed on it, like AWS CLI, Python and so on. You can read more about it here. Select an AMI and move on to the next step.
3. Select instance type
Based on your requirements/needs select the type of instance type that you need. In case you’re not sure, your requirements should determine things like “how much CPU or RAM memory do I need”. A t2.micro goes under the Free Tier Eligible tag, this means that is free to use for free tier users. I will use the t2.micro instance type for this example. Select the one you want and click the Next button.
4. Configure Instance Details
Please make sure you pay more attention to this page than to the others. This is where you configure your instance. AWS allows you to configure different things, but some of the most important ones have been highlighted in the picture above.
Please read more about the VPC here. In very simple terms, the VPC allows you to create a virtual network that you define. Your instances, in this case, can then be launched inside that VPC, simply put this offers you a lot of security and much more. I will be using the default VPC that I have, you can select another one from the Network dropdown or create a new one, in accordance to your needs.
Please read more about the VPC here. Again, simply put, an IAM role is an identity/role/user (whatever you would like to call it) that you can create and assign different policies that determine what the identity can and cannot do in AWS. For example, you can have an IAM role that is called “S3 Read Only Acces” and would only be capable of reading things from S3, not write or update anything in there, just read. I will not be assigning any IAM role to this instance, even though it’s always a good practice to assign one.
This determines what happens with your instance when you are shutting it down. You have two options at the moment: Stop or Terminate. In case you want to destroy the instance when you shut it down, select Terminate, otherwise Stop will do just fine. It will stop your instance, but not terminate it. I will choose Terminate for this tutorial, as I don’t need this instance to exists after I shut it down.
Enable termination protection
This will protect your instance from being accidentally terminated. It’s good to be enabled for critical systems or anything you don’t want to get rid of by accident. For this tutorial, I will not select this option, as I want to be able to easily terminate the instance afterward.
This option will be influenced a lot by your requirements. I usually use the Shared option, to stay under the free tier and just because I don’t need to have a dedicated hardware for my projects. Choose the one you want based on your needs.
Once you’re happy with all the configuration options, click Next.
5. Add storage
Please read more about the EBS Volume Types here. As AWS says in that little blue box, any free tier user gets up to 30 GB of SSD or Magnetic storage for free. The minimum size for the instance is 8 GB, but that is generally more than enough for most web applications. This storage will delete on termination, so any data in this SSD will be lost. For the purposes of this tutorial, the default one will be good enough. Click Next once you’re ready and move on to the next section.
7. Add Tags
The tags are a very good way of keeping track of what’s happening within your AWS account. This is great for companies where they have different teams working on different environments at the same time. They are not a requirement but is really good practice to use them. For this tutorial, I just added an example one. Click Next to move on to the next section.
8. Configure Security Group
Please read more about security groups here. The first sentence from their documentation defines it pretty well: “A security group acts as a virtual firewall that controls the traffic for one or more instances.”. It does exactly that, determines what traffic can access your instance. It’s quite important so make sure you always select the right security group for your application. As you can already notice, I have two security groups at the moment. The first one is the one created by default, by the VPC. The second one is the one created for my blog.
You can create a new one, but if you want to allow all the traffic to get to your instance, copy the Inbound rules I use for mine, that basically means that all traffic should be allowed. Please read the documentation carefully before creating your security group. It should reflect the requirements you have set for your project. Click Review and Launch.
9. Review and Launch
All you have to do here is review that the configurations are all correct and click Launch.
10. Download Key Pair
This step is extremely important. In case you don’t already have a key that you plan on using to access this instance, select Create new key pair from the drop-down. Add a suitable name and click Download Key Pair. You must download this key now and keep it somewhere safe as you won’t be able to get the key again from anywhere. You will use this key to SSH into the instance once is created.
Click Launch Instances once you have downloaded the key pair. That will start launching your instance. It might be taking a few minutes, depending on your availability zones.
That’s it. Those are all the steps to launch/provision an instance in AWS. You can check that your instance has been created successfully by going into the EC2 dashboard again and look at all the running instances.
You can check that the instance works by trying to SSH into it, using your private key. Below you can find two tutorial example that might help you SSH into your instance:
I hope you find this tutorial helpful. As always, leave your questions in the comments and I will be happy to help.