Amazon EC2 is without any doubt the most used AWS service that lets users launch and manage server instances, at any time and for as long as one needs. Here in this Amazon EC2 tutorial, we will learn what is EC2 in AWS and how it works. Towards the end of this Amazon EC2 tutorial, there is also a beginner-friendly demo to get you started with Amazon EC2.

What is EC2 in AWS?

The full form of Amazon EC2 is Amazon Elastic Compute Cloud. Amazon EC2 is one of the most used and most basic services in Amazon so it makes sense to start with EC2 when you are new to AWS.

Well, to be very simple, EC2 is a machine with an operating system and hardware components of your choice. But the difference is that it is totally virtualized. You can run multiple virtual computers in a single physical hardware.

Elastic Compute Cloud (EC2) is one of the integral parts of the AWS ecosystem. EC2 enables on-demand, scalable computing capacity in the AWS cloud.

Amazon EC2 instances eliminate the up-front investment for hardware, and there is no need to maintain any rented hardware. It enables you to build and run applications faster. You can use EC2 in AWS to launch as many virtual servers as you need. Also, you can scale up or down when there is an increase or decrease in website traffic.

The word ‘elastic’ in Elastic Compute Cloud talks about the system’s capability of adapting to varying workloads and provisioning or de-provisioning resources according to the demand.

Why Amazon EC2?

Now that we know the EC2 overview, let’s now move forward and understand Why exactly do we need Amazon EC2. AWS Elastic Compute Cloud provides a lot of benefits, let me give you an overview of what I am going to discuss.

  • Auto-scaling
  • Pay-as-you-go
  • Increased Reliability
  • Elasticity

Auto-scaling:

This is the benefit that makes most businesses opt for AWS EC2. It is already explained earlier how Netflix uses Amazon EC2 auto-scaling to its advantage and provides a crash-free experience.

Auto-scaling is basically providing resources according to the demand. They either scale up or scale down corresponding to the increase or decrease in demand.

Pay-as-you-go:

You will be charged by the hour, and you have to pay only for what you have used. A company, XYZ might be using 100 servers normally, and on Mondays, it scales down to 50 servers. So, it only has to pay for 50 servers those days, not the usual fee for the usage of 100 servers.

Even when you use your Amazon EC2 instances services for a few hours, you only need to pay for that time period and nothing more.

Increased Reliability:

AWS is spread across 20 worldwide regions with 61 availability zones (AZs) which helps your business when it is expanding. Also, this will increase the load speed of your application around the world.

You can always store multiple copies of your application in multiple AZs so that when one data center fails or loses data, the application will not fail completely.

Elasticity:

Instead of 10 low-configuration machines, you could rent a single high-configuration machine with an OS of your preferred choice for your application. Elasticity is the feature from which Elastic Compute Cloud got its name.

Moving on, let’s now see different types of Amazon EC2 Instance Types.

AWS EC2 Instance Types

AWS EC2 instance types determine the underlying hardware of the instances which are launched.

These are the broad categories of EC2 instance types that are offered by AWS.

 TypeMnemonic
General PurposeMac T-family: T2, T3, T3a, T4g M-family M4, M5zn, M5n, M5a, M5, M6gT  is for tiny M is for the main
Compute OptimizedC-family: C4, C5n, C5a, C5, C6gn, C6gC is for compute
Memory-OptimizedHigh Memory  X&Z-family: z1d, X1, X1e, X2gd R-family: R4, R5n, R5b, R5a, R5, R6gX is for eXtreme Z is for zippy R is for RAM
Accelerated ComputingF1 G-family: G3, G4ad, G4dn Inf1 P2, P3, P4F is for FPGA G is for graphics Inf is for inference P is for pictures
Storage OptimizedH1 I-family: I3, I3en D-family: D2,D3,D3enH is for HDD I is for IOPS D is for dense

There are several types of AWS instances with different configurations and benefits.

  • General purpose
  • Compute optimized
  • Memory-optimized
  • Accelerated Computing
  • Storage optimized

General-purpose Instances

General-purpose instances offer a good mix of compute, memory, and networking resources and can be used for a wide range of workloads. These instances are ideal for applications like web servers and code repositories that use these resources in equal parts.

A1 Instances

Amazon EC2 A1 instances offer significant cost savings and are ideal for scale-out and Arm-based workloads supported by the Arm ecosystem. They are the first EC2 instances powered by AWS Graviton Processors, which include 64-bit Arm Neoverse cores and AWS-designed custom silicon.

A1 instances are used in applications that work in synchrony with the Arm ecosystem and are suitable for scale-out workloads. They are suitable for these applications:

  • Web servers
  • Containerized microservices
  • Caching fleets
  • Distributed data stores
  • Applications that require the Arm instruction set

M4, M5zn, M5n, M5a, M5, M6g Instances

The M instance family is appropriate for small and medium-sized databases, data processing tasks that require more memory, cluster computing, and other enterprise applications. These instances offer a balance among compute, memory, and networking resources providing an ideal cloud design. It could be used for a wide range of applications. M5 instances are well-suited for the following applications:

  • Web and application servers
  • Small and medium databases
  • Gaming servers
  • Caching fleets

T2, T3, T3a, T4g Instances

These instances provide clock up or down of CPU performance. The T instance family includes burstable instances  are well-suited for the following applications:

  • Websites and web applications
  • Code repositories
  • Development, build, test, and staging environments
  • Microservices

Compute-optimized Instances

These instances are useful for compute-dependent applications that need high-performance processors. They are well suited for the following applications:

  • Batch processing workloads
  • High-performance web servers
  • High-performance computing (HPC)
  • Scientific modeling
  • Dedicated gaming servers and ad serving engines

C5, C4, and C5n are the instances under this category.

Graphics processing unit (GPU): The GPU instances provide a way to run graphics-intensive applications faster than with the standard EC2 instances. Examples of GPUs include Linux distributions often taking advantage of GPUs for rendering graphical user interfaces, improving compression, speeds, etc.

Micro: Serving as a small database server, Micro instance is meant for applications without low throughput.

Memory-optimized Instances

These instances are for delivering fast performance for processing large data sets in memory.

R4, R5, R5a, and R5d instances are memory optimized.

These instances can be used in these following applications:

  • High-performance, relational (MySQL) and NoSQL (MongoDB, Cassandra, etc.) databases
  • Applications which process real-time big data sets (financial services, Hadoop/Spark clusters, etc.)

Accelerated Computing Instances

These instances are the latest gen general-purpose instances, and they provide an accelerated performance when the CPU clock rate increases.

P3, P2, G3, and F1 are instances for accelerated computing.

P3 and P2 are general-purpose instances.

G3 is for graphic-intensive applications.

Storage-optimized Instances

Storage-optimized instances are designed for workloads that contain very large data sets which has to be written in memory and require high, sequential read and write access.

D2 instances feature up to 48 TB of HDD-based local storage and offer the lowest price-per-disk throughput performance on Amazon EC2.

H1 instances provide a balance between computing and memory and feature up to 16 TB of HDD-based local storage which delivers high-disk throughput.

I3 instances provide Non-Volatile Memory Express (NVMe) SSD-backed instance storage optimized for low latency, very high random I/O performance, high-sequential read throughput, and high IOPS at a low cost.

Managing AWS EC2 Clusters With ECS

In general, cluster management systems face two problems—the overhead from managing the state of the cluster and the assumed ownership of all applications while running tasks.

To tackle these challenges, ECS provides a simple solution to cluster state management such as the management of followers, dispatching of sub-tasks to proper locations, and state inspection of the cluster. ECS manages instances directly, rather than Spark or Hadoop managing them. To find out whether a sub-task is still running or not and what instances are available, you can call the ECS List* and Describe* API actions. This allows distributed systems to cut down on the amount of code, which further provides the ability to run multiple tasks on a shared pool of resources. This leads to higher utilization and faster task accomplishment than if the compute resources are statistically partied.

Amazon EC2 Instance Features

Many of the Amazon instances features are customizable such as storage, virtual processor, memory available to instances, etc. Below are some of the features of Amazon EC2 instance:

Elastic IP addresses: It can be moved from instance to instance without requiring a network administrator’s help. This helps in case of failover clusters, for load balancing, or for other purposes where multiple servers run at the same time.

Operating system: EC2 instance supports several OSes such as Linux, Microsoft Windows Server, CentOS and Debian.

Amazon CloudWatch It is used to collect, store, and analyze historical and real-time performance data. The CloudWatch service allows for the monitoring of AWS cloud services and applications deployed on AWS. It also actively monitors applications, improves resource use, optimizes costs, and scales up or down.

Automated scaling: Automated scaling helps in adding or removing capacity from Amazon EC2 virtual servers in response to application demand. Auto Scaling provides more capacity to handle temporary increases in traffic during a product launch.

Bare-metal instances: The virtual server instances consist of the hardware resources, such as processor, storage, and network. They are not virtualized and do not run an OS.

Amazon EC2 Fleet: As a single virtual server, Amazon EC2 Fleet enables the deployment and management of instances. It also provides programmatic access to fleet operations using an API. Further, Fleet management can be integrated into existing management tools.

Pause and resume instances: EC2 instances can be easily paused and resumed from the same state later. In case, there are too many instances running at the same time, they can be paused without incurring charges.

Persistent storage: EBS service enables block-level storage volumes to be attached to EC2 instances and be used as hard drives. With the help of EBS, it is possible to increase or decrease the amount of storage available to an EC2 instance and attach EBS volumes to multiple instances.

AWS EC2 Pricing

Generally Free Tier 750 hours of free usage up to one year is provided by AWS. Only t2.micro instance can be used on Linux and Windows AMIs.

On-demand Price:

m5.large$0.096/hour
c5.large$0.085/hour
r4.large$0.133/hour

Data Transfer IN:

FREE from any region in the world

Data Transfer OUT:

From EC2 to:

S3, Glacier, DynamoDB, SES, and SQS in the same regionFREE
S3, Glacier, DynamoDB, SES, and SQS in the same region$0.020/GB
EC2, RDS, Redshift, ElastiCache, ELB, and ENI in the same AZ with private IPFREE
EC2, RDS, Redshift, ElastiCache, ELB, and ENI in the same AZ with public IP$0.010/GB
EC2, RDS, Redshift, ElastiCache, ELB, and ENI in different AZs$0.010/GB

Knowing about EC2 in AWS is one of the first things one must do when they are starting with AWS but it won’t do any good if you don’t know how to create an EC2 instance. Now let us create an EC2 Instance to understand better.

log on to your AWS account and let’s create your first instance.

Demo: Creating an AWS EC2 Instance from scratch

Step 1Open the AWS Management Console, open services drop-down and click on EC2 under the compute category

Basic steps to follow in order to create an Amazon EC2 instance is depicted in the image below:

Step 2: Creation of an instance

  • First, click on Launch Instance
  • Now, in the Choose AMI section, scroll down and choose Ubuntu and click on Next
  • Choose the free tier eligible t2.micro Instance and proceed with Next: Configure Instance Details
  • Configure instance details and then click on Next
  • Next is adding storage. Here, you don’t need to change the size because for a basic Ubuntu instance it is 8 GiB
  • Now add a tag with the attributes Key and Value, name them as it is in the image below. Key and Value pairs are to identify the particular instance while it is running
  • Now proceed with the next step, Create a new security group, and then click on Review and Launch
  • Review your instance specifications once and then launch it

Step 3: Creating a new key pair

  • Choose Create a new key pair from the popup box, give a name for the key pair, and then click on Download Key Pair. Then, proceed with Launch Instances
  • Keep the downloaded key pair file in a safe location so that you can access it later


Step 4: Viewing your AWS instances

  • Wait till the launch is initiated, then click on instances under the INSTANCES option and view the instance which you have created
  • Wait till your instance initializes, that is, till your 2/2 checks are done

Now it gets interesting; here, you will connect the instance using an SSH client and then host your own website

Step 5: Connecting the instance through an SSH client

  • Download PuTTY: a free SSH client

Website link: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

  • Choose 32 or 64 bits according to your system’s specifications. Then, install it like you install any other application on your system
  • Install PuTTY
  • PuTTY only accepts private key files with the extension ‘.ppk’, so you have to convert your ubuntudemo.pem to a .ppk extension
  • Now, open PuTTYgen and load ‘ubuntudemo.pem’. A dialog box appears where you have to press OK
  • Click on save private key and proceed with a Yes in the dialog box. After that store it in a location from where you can access it easily
  • Open PuTTY, type ubuntu@”your public ip” which you can find in the description tab for your instance
  • First, type Host Name in the box with the port number, 22
  • Second, go to Connection → SSH → Auth. Now, click on Browse and add the .ppk file which you have created
  • Click on Open and then press Yes on the PuTTY Security Alert box
  • Now, you have successfully launched your Ubuntu instance!

Step 6: Running a simple HTML page via this instance

  • First, update the Ubuntu instance using this command
  • Then, install apache2. Apache2 is a web server which is commonly used in Linux systems
  • Type the below commands to enter into that directory and check whether index.html exists
  • Go back to your instances page and click on ‘launch-wizard-4’ under security groups
  • Go to Inbound and click on Edit. Then, add an HTTP rule with Source as ‘Anywhere’
  • On your browser, use your public IP address, put it in the URL box and run
  • You have now successfully hosted your first website via a Cloud instance
  • Let’s now see how to edit and run your own HTML page instead of the Apache2 default page
  • For one last time, run the public IP address of your instance in the browser

Congratulations! You have created your first Ubuntu instance and have run your webpage on it!

Hope this Amazon EC2 tutorial was helpful to you. Do let us know in the comment section below.

Watch this AWS EC2 tutorial video:

Leave a Reply

Your email address will not be published. Required fields are marked *