How to choose the right EC2 Instances
AWS (Amazon Web Services) is the biggest cloud computing service in the world with a market share of 31% (https://www.tharawat-magazine.com/facts/top-5-largest-cloud-companies-world/). With a vast array of services which include VMs (Virtual Machines) for compute operations (EC2, Elasticbeanstalk, Lambda and Batch). Storage; S3 (Simple Scalable Storage), EFS (Elastic File Storage), EBS (Elastic Block Storage), Glacier, Storage Gateway and many other services for AI, Security, Database, Networking, IoT, Analytics.
But here is not the discussion for all these services and how they can be designed to work together to perform a lot of great tasks and achieve a beautiful cloud engineered eco-system. In this discourse we shall be talking about how to choose the right EC2 Instances. For AWS using we know how much we love our EC2 instances, (mostly those of us under the Reserved and On-demand Instance category). AWS has given us powerful interfaces to aid the ease of creating Virtual Machines with simple operations. You can either choose to your the AWS Management Console, AWS SDK which is almost in any language also the AWS CLI for those who love their command line.
With AWS, you have been given the liberty to do almost anything you want; from allocation of any type of resource (disk, memory, CPU, GPU, etc) to any type of operating system(Windows, and Linux Distros). But proper use of these tools putting certain factors into consideration; such as cost and scale is the best way to go. So you do not end up using a sledge hammer to kill a mosquito, what a simple insecticide will do the same job and achieve the purpose with less stress involved.
Before any instance is created, it is pertinent that the application, services, and the stack of the application is critically understood. A sample list of checks include:
- Does it consume alot of memory ?
- Is it CPU intensive ?
- Will I need to store data within the application ?
- Is there some image processing going on ?
- How is scale handled when there is an incident ?
- What type of web server does the application need ?
The checklist could go on and on, but what is important is understanding the stack of what is to be deployed and if using an EC2 instance is the right way to go, also choosing the right instances.
To create an EC2 Instance you can either use SDK, CLI or Console but for this course we shall be using the AWS Management Console which is the GUI form for creating instances.
AWS has made it flexible enough for you to select the instance based on what you are doing, or what your language requires in terms of resources. Is your language CPU Intensive ? Is it memory intensive ? Or am I processing high resolutions images or processes that will need a high GPU ? These are questions that need to be answered before taking the next step to setup an EC2 instance.
You can see the types of instances here and the categories
A language such as PHP which has high demand for memory, it is recommended that you take an r4 category of instance. An example of this type of instance is the r4.large, which goes for $106.56/month (region and OS dependent see here: https://aws.amazon.com/ec2/pricing/on-demand/). This comes with 2 vCPUs and 15.25GiB of memory. The memory used on this instance has been specially optimized for memory demanding operations.
On the flip side, NodeJS which is a non-blocking I/O language requires a lot of CPU when under load this will require that a CPU optimized instance is used in this scenario. An example of the type of instance that can be used for this is c4.large (2vCPUs and 3.75GiB of memory)which is the least that exists and costs about $81.36/month (region and OS dependent).
So it applies accordingly but there are some cases where you just do not even know the type of instance to use, maybe you are just a hobbyist or you want to play around or out-rightly not sure of what you want to use. AWS still got you covered with the EC2 General Purpose Instances. These are the t2, m3, and m4 instances. These are built with optimization CPU, GPU and memory resources to optimum performance. The least of this is the t2.nano (1vCPU, 0.5MiB) Instance which costs about $4.32/month. There is also the t2.small (1vCPU and 2GiB of memory) and t2.medium (2vCPU and 4GiB of memory) respectively. These machines can be used for almost any case scenario will give you optimum performance and throughput. But when the activities of you systems and application begin to scale up and maxing out the resources on those machines, be it memory or CPU resources, it is advisable to start looking at resource optimized instances so as to get the best performance.
The resource optimized Instances have been specially designed to special purposes, it is best they are used for what they are designed for so as to get the best performance.
Also you have to look at your pocket when picking these instances, because if you do not choose rightly you end up spending so much when you would have used a lesser resource and still get a good performance. So it is important you choose the right resource at a minimum, setup monitoring tools in your infrastructure and monitor your application so you know when to scale up and down resource/instance (Vertical Scaling) or employ Autoscaling (Horizontal Scaling)
This is where I will draw the curtain about selecting the right instance type for the right purpose with factors like cost and giving your system/application high availability

