So you decided to start using AWS as your cloud provider. Well, there are a lot of services that can be used on the go, but one of the most basic and probably the most common is Amazon EC2. In this blog, you will see the basic concepts and we'll tell you step by step how to create EC2 instances.
What is Amazon EC2
EC2 (Elastic Cloud Compute) is the service where you can create servers (from now on I’m going to call them instances since it’s the name used inside AWS) to launch your websites or applications.
Why Use Amazon EC2
Since there are a bunch of other providers on the network which can host your app, we choose Amazon EC2 because it offers a lot of possibilities. You can start with a small instance and then when you get more traffic, grow it up to a bigger option; making EC2 more flexible and adaptable than other technologies to host your application.
It is easy to increase your hard drive size in case that you need to store more code or images for your app. Without mentioning that you are two clicks away to start using the load balancer on AWS, considering that you just literally have to select your load balancer and add an instance to it. The thing is that most of the common hosting users are afraid of how much AWS would cost, but considering its capacity and flexibility, your application will be in good hands on AWS.
AWS has more time on the market, so the services have been improved since it started, refining them every year for better user experience and technology innovation. All of these reasons made AWS the top provider chosen by millions of companies around the globe.
EC2 Instance Types
One of the first things that you are going to find when you try to create your first EC2 instance, is the instance type/size. There are several options to choose for each kind of workload that you want to do.
General Purpose EC2 Instance
This kind of instances are used the most for testing purposes. General purpose instances are divided into "T" and "M" varieties.
"T" instances are targeted to simple jobs just like testing environments, and they have a modest networking on the most basic options. So in general, they are not your choice if you want a production environment. On the other hand, if you are taking the option for your dev or staging environments, you should give them a try.
"M" Instances are for general use when you don't want a testing environment, but you want an all-purpose instance. They offer more balanced resources compared to "T" instance, so if you are looking for an instance for your production environment and you don't want to worry a lot about the resources, “M” instance is what you are looking for.
Note: “T and M” instances offer two types of virtualization; PV and HVM. The first was the one provided by AWS in the past, and it’s available on t1 and m1 instance types. I wouldn't recommend it because you can't take advantage of all the hardware, and in some cases are a bit slower.
Another restriction is that you are going to be able to increase your instance type to instances only based on PV, and the newer instance types are not going to be available. My suggestion is always to use HVM instances.
If your application requires to process a lot of information like math operations, load balancing, rendering task or sometimes video encoding, you need an instance that can process all that information in less time. "C" instance is your ally in this stressful operation since it has more CPUs capacity and lower RAM.
If your app doesn't require too much CPU, but instead, it needs more and faster RAM; you should check out the available option on the “X1e, X1 and R” instances.
“X1e” instances are targeted for high-performance databases or in RAM application, but it’s commonly used just by enterprise applications. This instance (x1e.32xlarge) type has an option with almost 4TB of RAM, and it’s certified by SAP to be used with the Business Suite S/HANA.
“X1”, like “X1e”, is targeted to enterprise applications but that require fewer resources, but they are also a pretty good option for Big Data operations and high-performance computing but instead “X1e” options we only have two options to choose with “X1” instances.
“R4” instances are the new generation of “R” instances, an excellent choice for data mining and data analysis and in memory applications such as databases, they have more accessible options with resources that a common user can choose.
“R3” instances are the old generation of the “R” instances, and compared with “R4” are expensive, so if you are considering this option, you better choose “R4”.
Creating a movie and need to render the textures? Need to design with power? Or you just have money to spend and want to play games on streaming? If you feel identified, P and G instances are what you are looking for, all these instances have their own NVIDIA Graphics card and vary the amount of GPU that they have depending on the instance size.
“P2” it’s a “general” purpose instance, but the older version of the “P” instances are more accessible compared with the new ones offer the power that you need for data science, data analysis, and rendering power.
“P3”, the latest version of the “P” instances, offer more power with its NVIDIA Tesla V100. Like the “P2”, this is an excellent option for data analysis, but it’s also going to be incredible at speech recognition and for autonomous vehicles.
“G3” instances are perfect for creating your remote graphics station, the best option for 3D rendering, video encoding or application streaming (yes you can stream an application which requires too many resources, even run a game and stream it to your laptop).
This Kind of instances are provisioned with a more significant amount of TB for storage, and you are going to have the best I/O Performance. These instances are a great option for those databases that need to be writing regularly on the disk, here we have three groups of instances: H, I and D.
“H” instances are the best option for distributed file systems or centralized log processing.
“I” instances are also a great choice for databases especially for NoSQL or data warehouse
“D” instances similar to H ones but offer better performance for Massive Parallel Processing data warehousing and distributed computing like Hadoop and MapReduce.
These are all the available instance types and some of their uses I hope with this little explanation it’s easier to you to choose from one or another.
What’s An AMI
AMI it’s the acronym for Amazon Machine Image. Pretty clear right? I don't think so. To make this a bit easier to understand, I'll give you an example.
If you have worked with old computers or even with physical servers, you probably know that you need to update or install the same stack on more than three devices. This is done by using tools like Norton Ghost or Acronis True Image to create disk snapshots which let you take a picture of the current state of the disk to load it on the other devices in less time, compared to doing it manually.
Well, an AMI has the same idea, but it is a combination of multiple snapshots. This means that if the instance has more that one disk the AMI it’s going to contain the other disks.
That’s the theory, but you also have to know that all the OS
offered by AWS are packed as an AMI so that you can find empty images with Ubuntu, Fedora, Centos, RedHat, Amazon Linux, even with Windows Server.
There are other AMI's options on the marketplace with preinstalled software like LAMP and LEMP stacks, Redis optimized or hardened software to launch your brand new instances. But be careful my friend, some of those marketplace AMI are not only smiled, some of them include a fee per hour for you to use it (plus the cost per hour of the instance). So, if you want to choose an AMI from the AWS Marketplace check the prices of it.
Note: To Use some of the instances you need to accept an agreement, sometimes you are going to be redirected to the AWS Marketplace to take it and, in other cases, you will have to access the marketplace to accept it.
How to create EC2 Instances and launch them.
Now you know the basics of the EC2 service and know that there are a lot of options and things to do. But the most important thing is to apply the knowledge. So let's see how to create EC2 instances and launch them using an AWS Marketplace AMI so you can see the complete process to launch your very first EC2 Instance.
This tutorial will show you how to create EC2 instances from scratch, but if you already have a WordPress site to migrate from cPanel you can check this tutorial.
1 x AWS account (if it’s an IAM user verify that you have permission to launch EC2 instances)
First of all, we need to login into the AWS Console, access using this URL: https://aws.amazon.com/console/and you are going to see this page, click the button “Sign In to the Console.”
It’s going to open a page requesting your username or email.Type your password.
This it’s what the AWS console looks like
Click on EC2.
This is how the EC2 Dashboard looks.
Click the big blue button “Launch Instance.”
Immediately after you click the button a list of AMIs is going to appear. There you can select the one that you prefer, in this case, I’m going to choose Ubuntu Server 16.04 LTS.
After you click the select button of your chosen AMI, you are going to be able to select the EC2 instance type from the list, for this example, I’m going to use t2.micro, select and the next button.
The next page is going to show you some options to set up your instance. For the moment, just be sure that the Auto-assign Public IP it’s set to enable and click next.
Now, on this page, you can choose the amount of GB that your hard drive it’s going to have.
Note: Never leave the default 8gb, if you want to be on the free tier limits you can set a value around 20gb -24gb, because sometimes you leave it as default and your instance is not going to have too many spaces to do many things, and click next.
Auto-scalable WordPress Multisite on AWS EC2?
Yes, we did this.
You should be on the Tags screen.
Let's click on the button “Add Tag” and on the key column type “Name” and on the value type the name that you want to give to your instance and click on next.
Setup a Security Group: A Security group it’s like the firewall for your instance. Here you have to open the ports that you are going to use: i.e., if you want to have a web server you need to open the port 80 if you want ssh access you need the port 22, so let's create a new one.
Let's give a name and description to the new Security Group.
Ports: The port 22 (ssh) open world (0.0.0.0/0) is added by default; we can leave it like that or choose “my IP” on the list of the source column. As a security measure, AWS only open ssh port to the ones that you trust and don't leave it open world, add a description to identify and click on “Review and Launch.”
A Summary of all the setting that you have set it’s going to be shown on screen if everything looks fine, click on Launch, if not you can return to change everything that you need.
A key? This little thing is what you need to be able to access your brand new instance. Give it a name and click the button “Download Key Pair.” Then, save that file because you are not going to be able to get it in another time. AWS doesn't store keys, so if you lose it, you are going to lose access to your instance.
Click on “Launch Instances.”
If everything goes well you are going to see the next screen, click on the id to view it on the dashboard.
Access to the instance
On the image above you can see the public IP of the instance. Save it, since we are going to use for access purposes. To access using Linux or Mac, you need to change the permissions of the key before using it.
For copy/paste purposes:
chmod 400 YourKeyName.pem
Time to get connected to the instance. You need to know that since we have launched an Ubuntu Instance, the user it’s Ubuntu, you can check this information on the AMI information.
Since is the first time you are going to get connected it’s going to ask you if you want to trust on the remote host (your instance) type “yes” and press enter, and you are going to get in.
If you are using windows depends on the tool that you are using, let us PuTTY, this tool doesn't accept pem files, so we need to convert the file using a tool provided by PuTTY: PuTTYgen.
Click on load and choose your pem file and you are going to see the loaded key, just press “save private key.”
It’s going to ask you if you want to add a passphrase (another layer of security) just press yes to continue without it.
And save the file, this it’s going to create a file with the “.ppk” extension.
Now let us it to get connected using PuTTY
On hostname type
Now like on the image above click on the + on the left to SSH and select Auth, there click on the browse button and select the ppk file created by PuTTYgen and click open.
Same as happened on Linux it’s going to ask you if you want to trust the host, just click yes, and you will be there.
And you are in
With this you know the basics of AWS EC2, some concepts, you know how to launch an instance and how to access to it if you have any doubt feel free to post it on the comments section, hope you enjoyed this fast tutorial.