DEV Community

loading...

Everything you need to know about EC2! Part 1

frontendexp
Mobile and Web development
Originally published at aws.plainenglish.io on ・8 min read

Everything you need to know about EC2! Part 1

AWS led a big change in the entire industry by being the very first cloud provider and by introducing EC2 as the first virtual machine running in a public cloud.

Agenda
EC2 Overview
EC2 Types of Launch Instances
What is EC2?
You can think of EC2 as a virtual machine running in a public cloud.
With EC2, you pay only for what you use, you only pay for the time when your EC2 instance is up and running.
It’s a pay-as-you-go model, and this really changed the economics of computing.
With EC2, you should be able to avoid a lot of the wasted capacity which is inherent in physical servers, and this is because with EC2, you can select the capacity that you need right now, and you can grow and shrink as and when you need.
The real massive benefit for a lot of companies is that with cloud computing, you can have your servers up and running in minutes rather than waiting months for setting everything up in a data center.If you’ve ever worked in a large organization, you’ll know it can seriously take a minimum of 3 months at least to get a new server up and running in your data center. So why is that? Well, firstly, after getting approval to spend the money, you’ve got to then make the purchase, and then you might wait maybe 2 or 4 weeks for the hardware to become available and to be delivered. Once it’s actually been delivered, we’ve then got to get it physically installed in the data center. Then the data center engineer has to find a space in the data center to install our server.
We’ve then got to patch our network cables and get it on the right network, and then our sys ops team will install the operating system along with any monitoring and backup and security hardening software as well, and all of this takes time.

Photo by Aron Visuals on Unsplash
So there are many stages we have to go through before we can actually install an application on our server, and this is why in some organizations, depending on the level of change control and approval process involved at each of these stages, in some cases, it can take 3 months or longer to purchase a new server and have it up and running and ready for you to install your application.
EC2 mainly consists of:
Renting virtual machines (EC2) (Part 1, this article )
Storing data on virtual drives (EBS)
Distributing load across machines (EBL)
Scaling the services using an auto-scaling group(ASG)
EC2 sizing and configuration options
Operating system: Windows, Linux, Mac OS

  1. How much compute power & cores (CPU)
  2. How much random access memory (RAM)
  3. How much storage space
  4. Network-attached (EBS & EFS)
  5. Hardware (EC2 instance store)
  6. Network card, speed of the card, public IP address
  7. Firewall rules, security group
  8. The bootstrap script, configured at the first launch If you go on the AWS management console, search for EC2, access it, and press launch instance, you will be asked to configure it in regard to all the aspects mentioned just above.

So what does bootstrapping mean? Well, bootstrapping means launching commands when the machine starts.
So, that script is only to run once and when it first starts, and then will never be run again.
So the EC2 User Data has a very specific purpose. It is to automate boot tasks, hence the name bootstrapping.
Example of a bootstrap script:

!/bin/bash

yum update -y
yum install httpd -y
echo "

Hello World

" >/var/www/html/index.html
systemctl start httpd
systemctl enable httpd
So what tasks do you want to automate?
Usually, when you boot your instance while you want to install updates, install software, download common files from the Internet, or anything you can think of really, anything you can think of. EC2 User Data script runs with a root user. So any command you have will have pseudo rights.
EC2 instance types basics
Here: https://aws.amazon.com/ec2/instance-types/
So there are different types of EC2 instances that you can use for different use cases and they have different types of optimization.
AWS has a naming convention. For example, we’ll be talking about an M5.XXL type of instance. What does that mean?

Well, M is going to be called the Instance Class.
And this is going to be, for example, in this case, a general-purpose type of instance, five is the generation of the instance.
As AWS improves the hardware over time if we release a new generation of hardware, and so after M five, if they improve the M type of instance class then we’ll go to M six and then finally the two X large represent the size within the instance class.
It starts as small and then large and then two X large four X large and so on.

So it represents the size of the instance, and the more the size, the more the memory the more the CPU is going to have on your instance.
So from an exam perspective, what do you need to know? Well, we’ll talk about a few different instance types.
So you have a general purpose and these are great for diversity of workloads such as web servers or code repositories. They will have a good balance between computing, memory, and networking.
Then we have compute-optimized, and these instances are great and optimized for compute-intensive tasks.
So what requires a high level of the processor?
Well, for example, it could be if you’re batch processing data, if you’re doing media transcoding, if you need high-performance web servers, if you’re doing a high performance, computing is called HPC. If you’re doing machine learning or if you have a dedicated gaming server. So all these things are tasks that require a very good CPU and a very good compute side.
And so EC2 instances do have this kind of particularity and for now, all the computer optimized instances in EC2, are of the C names.

So C5, C6, and so on. Next, we have some EC2 instances that are memory-optimized and are going to have a really fast performance for the type of workloads that will process large datasets in memory.
Use cases that are going to be high performance for relational or non-relational databases are mostly going to be in-memory databases, distributed web-scale cache stores. Could be used for elastic cache, for example, in-memory databases that are optimized for business intelligence or BI.
And applications performing real-time processing of big unstructured data.
So in terms of the names for the memory-optimized instances, there’s going to be the R series because R stands for RAM but there’s also going to be X one high memory and Z one.

And finally, we’ll have storage optimized instances.

They’re great when you are accessing a lot of data sets on the local storage.
And so the use cases for storage optimized instances are going to be high-frequency online transactional processing, so OLTP systems.
Relational and NoSQL databases.
Cache for in-memory databases, for example, Reddit’s data warehousing application distributed file systems and the search optimized instances in AWS will start with an I, a G, or an H one.
So what does it mean?
Let’s compare a few instance types.
So for example, for t2.micro we have one VCPU and one gigabyte of memory.
And if you look for example, at r5.16xlarge we have 16 VCPU and 512 gigabytes of memory.
So we can see there’s a lot more emphasis on memory. If we compare it to an example, to a c5d.4Xlarge. We can see we have 16 VCPU and 32 gigabytes of memory.
So less memory, more CPU, and so on different network performance different EBS bandwidth and so on.
Instances.vantage.sh — Compares all of the instances of EC2.
EC2 Instance Launch Types
On-Demand Instances: short workload, predictable pricing, pay by the hour or second, depending on the type of instance you run.
Reserved Instances / Saving Plans: Reserved capacity for one or three years. Up to 72% discount on the hourly charge. Regional. Also includes serverless technologies like Lambda and Fargate.
Spot Instances: Purchase unused capacity at a discount of up to 90%, prices fluctuate with supply and demand.
Dedicated Instances/Hosts: A physical ec2 server dedicated for your use, the most expensive option.
Now with these different types, there are different pricing models.
So let’s start with on-demand, which is the default.
So with on-demand, you pay by the hour or the second, depending on the type of instance you’re running. You only pay for the time when you are running your instance.
For more information on this check
https://aws.amazon.com/ec2/pricing/on-demand/
With reserved instances, you can reserve EC2 capacity for either one or three years.
You commit to using a certain amount of EC2 instances of a specific type for either one or three years and in return for making this commitment, you get up to a 72% discount on the hourly charge and reserved instances operate at a regional level.
For more information on this check
https://aws.amazon.com/ec2/pricing/reserved-instances/
Spot instances are where you can purchase unused capacity at a massive discount of up to 90% and the price fluctuates according to supply and demand.
You set a maximum price that you’re willing to pay for the instance, but the catch is that as soon as the price exceeds your maximum, the instance will be terminated or hibernated depending on the options that you’ve chosen. You get a massive discount, but it’s not really suitable for every application.
For more information on this check
https://aws.amazon.com/ec2/spot/?cards.sort-by=item.additionalFields.startDateTime&cards.sort-order=asc
Dedicated hosts/instances: it’s actually the most expensive option, but it’s a good option If you have software licenses, which are tied to physical hardware, or if you have very strict compliance requirements. Can be purchased On-Demand (hourly) and it can also be purchased as a Reservation or Savings Plan for up to 70% off the On-Demand price.
https://aws.amazon.com/ec2/dedicated-hosts/pricing/
There are very important topics to cover on EC2. This particular article is very focused on the EC2 instance types and pricing models. Very Theoretical.
But it’s very important to actually get your hands on EC2 and try to launch an EC2 instance and access it via SSH, Putty, and EC2 Instance Connect.
In the table below you can see there are different ways and different requirements to access the EC2 instance after you launch it.

In future articles, I will add some hands-on guides, regarding EC2.
Also, there are still a few theoretical topics to cover that are related to EC2, like EBS, EBL, and ASG as mentioned at the beginning of this document. But also, how to use EC2 with S3, RDS, Route 53, and Elastic Cache. Stay tuned for those upcoming topics.

Discussion (0)