Amazon EC2 – AWS Elastic Compute Cloud

Filed Under: AWS
Aws Ec2

Amazon EC2 is an abbreviation for Elastic Compute Cloud. It’s elastic in nature which means you can scale it at any point in time. It’s very hard to predict the compute power for application deployment. Sometimes, you need more compute power and sometimes less. In both cases, you have to decide the compute power well in advance. Because it takes a lot of time in the procurement of hardware resources and set them up.

AWS EC2 solves on-demand scalability issue of the On-premises deployment. In this tutorial, we will launch an AWS EC2 Linux instance to understand the concept.

You will notice that throughout the tutorial, somewhere I will mention “Amazon EC2” and somewhere it will be “AWS EC2”. They refer to the same software and can be used interchangeably.

What is Amazon EC2?

Amazon Elastic Compute Cloud (Amazon EC2) provides elastic computing capacity in the Amazon Cloud. When we say elastic that means it’s scalable at any point in time. With the Amazon EC2, you can launch as many virtual machines as you want. Which reduces the upfront cost of hardware purchase. You can grow or replicate your infrastructure services as your business grow.

AWS provides you with the web interface to launch the AWS EC2 instance. It provides ready to instantiate AMIs (Amazon Machine Images) to quickly launch an EC2 instance.

If you are not familiar with Cloud Computing then read our post on “Overview of Cloud Computing” and “Amazon Web Services (AWS)”.

Service vs Instance

It may be confusing for beginners that sometimes we say service and sometimes instance. So, EC2 is web service provided by AWS but we use it through an instance like t2.large instance.

In general, a machine instance is a virtual machine running in the cloud. All applications that you deploy run on this virtual machine itself. These virtual computing environments are knowns as instances.

Why EC2?

One of the key reason for using AWS EC2 is the opportunity to replace upfront infrastructure expenses with low variable costs that can scale with your business.

Let’s talk about the more exciting features that AWS EC2 offers.

  1. It provides the virtual computing environment known as instances.
  2. EC2 service is elastic in nature – Scale when your business grow.
  3. Pay-as-you-go pricing model.
  4. Preconfigured templates available for your instances, known as AMI (Amazon Machine Images).
  5. Web interface available to do the various configurations of CPU, memory, storage, and networking capacity.
  6. Elastic Ip addresses are available – Static Ip address for your dynamic cloud computing.
  7. Secure login for your instances with key pair (Public Key and Private Key).
  8. Persistent storage volumes for your data known as Amazon Elastic Block Storage (Amazon EBS).
  9. Highly Reliable – multiple physical locations for your data.
  10. Integrated Environment – EC2 is integrated with almost every service available on AWS. You do not need to do POCs (Proof of Concept) and research.
  11. No additional IT team is required to manage your deployment.
  12. You are not buying hardwares – You can release services whenever you want without worrying about the investment cost.

You will find many reasons why to use AWS EC2 when you will actually start using it. Tell us your favorite reason in the comment section.

EC2 Instance Types

AWS offers several EC2 instance types and each of them is for particular use cases. Each instance type offers a different memory, computer, and storage capabilities.

AWS grouped EC2 instances based on these capabilities and provides the below-listed instance types:

General Purpose Instance

These instances provide a good balance of memory, computer, storage, and networking resources. And can be used in a variety of use cases and workloads.

T2 and T3 Instances

T2 and T3 are the Burstable Performance Instances. These instances provide you the baseline CPU performance but have the ability to burst to a higher level based on the workload.

These are only instances which use the credits for CPU usage. Just for your information “One CPU credit is equal to one vCPU running at 100% utilization for one minute.”

These instance types are the perfect candidates for :

  1. Web Applications
  2. Websites
  3. Microservices
  4. Code Repositories etc.

M4, M5, M5a, and M5d Instances

These instances are well suited for below type of applications:

  1. Web Servers
  2. Application Servers
  3. Small and Medium databases
  4. Gaming Servers

A1 Instance

These instances are well suited for below type of applications:

  1. Distributed data stores
  2. Containerized Microservices
  3. Web Servers etc.

You can check the summary of hardware specification like default vCPUs, Memory (GiB) on AWS. Based on you hardware requirement you can choose the machine type.

Compute Optimized Instance

Compute-optimized instances focus on providing you the high-performance processors. These types of instances are ideal for compute-bound applications.

C series (C4, C5, C5d, and C5n) Instances

These are the good candidates for below types of applications:

  1. High-performance computing
  2. Batch Processing
  3. Compute Intensive Applications
  4. Machine Learning etc.

Memory Optimized Instance

As per the name suggests these are designed to provide you fast performance on the large dataset in memory. Memory Optimized instances are being used mainly for the database services.

R Series(R4, R5, R5a, and R5d) Instances

These types of instances are the good candidates for the below types of applications:

  1. High-performance relational and NoSQL databases like MySQL and MongoDB
  2. In memory caching – Redis and Memcache
  3. Big Data like Hadoop/Spark clusters

Accelerated Computing Instance

These instances provide very high processing capability for the GPUs (Graphics Processing Units). There are several instance types available under the Accelerated Computing Instance like F1, P2, P3, G2 and G3.
These are well suited for the below types of applications:

  1. Video Creation Services
  2. 3D Visualization
  3. Video Encoding
  4. Virtual Reality
  5. Deep Learning
  6. Molecular Modeling etc.

Storage Optimized Instance

Storage Optimized Instances are highly optimized to provide low latency, IOPS (I/O operations per second) to your application.

H1 Instances

These instances are the good candidates for the below type of applications:

  1. MapReduce and distributed file system
  2. Require high-throughput access to the big chunk of data

D2 Instances

D2 instances are the well suited for the below types of applications:

  1. Parallel Processing
  2. Log processing applications
  3. Data processing applications

I3 Instances

I3 instances are the well suited for the below types of applications:

  1. Relational Databases
  2. NoSQL Databases
  3. In-Memory Databases (like Redis)
  4. Online Transaction processing (OLTP) systems

Instances from AMIs

AMI is an abbreviation for the Amazon Machine Image which provides the essential information to launch a virtual machine in cloud. You can launch multiple identical instances from an AMI.

An AMI contains three things:

  1. Template – For the root volume for the instances (An application server, an OS, and applications)
  2. Permissions to Launch – Which account can use this AMI to launch instances
  3. Block device mapping

We will discuss the Amazon Machine Images in detail in a separate post. There we will learn how to create, register, use and deregister the AMIs.

Setup AWS EC2

Most of the services provided by AWS are linked together. So, let’s launch a Linux EC2 instance and explore the services for how they work.

Setting Up

To get started, make sure that you have an account on AWS and that has been activated.

  • Login to AWS Console
  • Explore the Services Tab
  • Search for EC2
  • Click on EC2 service under Compute – Note: If you have already used it then it will appear in history section as well.

If you are able to perform all the above actions then you are good to go. Let’s launch a instance now.

Launch Instance

You will redirected to the EC2 dashboard. You will see something like the below screen. In the middle section, you see two things:

  1. Resources – Currently we have zero instances running.
  2. Create Instance – To launch the new virtual instances.
Ec2 Resource Create Instance Ec2

Click on the “Launch Instance” button.

Step 1: Choose AMI

I will choose an existing AMI to launch the virtual machine. If you see there is a section in “My AMIs” for the images that you created.

To give you a quick start, AWS provides you with a number of Amazon Machine Images (AMI) by default. We are going to use Linux instance from AMI “Amazon Linux 2 AMI [HVM], SSD Volume Type”.

Step 1 Choose AMI

Click on the “Select” AMI and continue.

Step 2: Choose Instance Type

Now, you will see the list of instance types that we were just talking about. You can filter and find the instance type that you want based on your use case.

I’m choosing t2.micro type, since it’s free tier and my account, is eligible. So I will get by default: t2.micro (Variable ECUs, 1 vCPUs, 2.5 GHz, Intel Xeon Family, 1 GiB memory, EBS only)

Step 2 Choose Instance Type


Clicking on “Review and Launch” will launch the instance with the default settings. Click on the “Next: Configure Instance Details”.

Step 3: Configure Instance

You will see the below screen with several configuration options:

Step 3 Configure Instance Details
  • Number of Instances – You can choose to launch more than one instance at a time.
    Note : Please ignore the “Launch into Auto-scaling Group” for now. We will talk about this in scaling up your application.
  • Purchasing Option – Check this if you want to buy Spot Instances. This lets you specify the maximum price you are willing to pay per instance hour.
  • Network – AWS create a default VPC for you. You can create a VPC and select your own IP address range, create subnets, configure route tables, and configure network gateways.
  • Subnet – is a range of IP addresses in your VPC that can be used to isolate different EC2 resources from each other or from the Internet.
  • Capacity Reservation – reserve capacity for your EC2 instances in a specific Availability Zone

You can leave all the options with their default values for now. I just wanted to let you know that what are these options and their usage.

Now, click on “Next: Add Storage” button.

Step 4: Add Storage

Let’s add storage to your instance. One thing to notice here is that default Size (GiB) is 8 GiB. You can add the storage that you want.

Step 4 Add Storage

Note : Free tier eligible customers can get up to 30 GB of EBS General Purpose (SSD) or Magnetic storage.

Delete on Termination – EBS volumes persist independently from the running life of an EC2 instance. After 12 months if you don’t pay then AWS will delete the storage on termination.

Now, click on the “Next: Add Tags” button.

Step 5: Add Tag

Tags are used to label an AWS resource. Tag consist of a key and pair(optional). See the below screen:

Step 5 Add Tags

Now, click on the “Next: Configure Security Group” button.

Step 6: Configure Security Group

Security groups control the traffic to reach your instance. You allow certain ports and protocols to get access.

Step 6 Configure Security Group

Note: Rules with source of 0.0.0.0/0 allow all IP addresses to access your instance. It highly recommends setting security group rules to allow access from known IP addresses only.

Now, It’s time to review the instance that we configured and launch it by clicking “Review and Launch”.

Step 7: Review Instance

Now, It’s time to see your instance before launch. A review screen will all the options and details that you have selected in the above steps.

Step 7 Review Instance

Step 8: Create Key Pair

Now, please create a key pair. A key pair consists of two keys 1) Public Key 2) Private key. Key will allow you to connect your instance securely.

Step 8 Generate Key Pair

Note: Please make sure that you store the .pem file somewhere securely on your Desktop system for further use.
Finally, launch instance by clicking the “Launch Instances” button.

Launch Instance Status

AWS takes a few minutes to launch your instance. You will see the below screens while AWS is processing in the back for your instance.

Step 9 Launch Status

Once the instantiation has been completed you will be shown another intermediate status screen. This is in case you want to see the logs of instance launch.

Step 10 Launch Status

On this screen, scroll down and you will see a button “View Instance”.

View EC2 Instance

Now, your instance has been launched and you can see the instance details on the same Dashboard from where we started in Step -1.

Step 11 Instance

See in the left toolbar there are many options available. We will talk about each of them in detail in other posts to give you end-to-end understanding.

Connect to EC2 Instance

You can directly click on the “Connect” button. OR Click on the button “Actions” on the top and you will see the below options.

Step 12 Instance Details

On clicking “Connect” button, you will see the below options to connect to your EC2 instance.

Connect Instance

Connecting through the SSH is straight forward, you can use console or putty to connect through the SSH client.

I will show you how to connect through a Java SSH Client from your browser. Make sure that you have Java installed on your machine. Otherwise, this option will not work for you.

Connect Through Java

Give the path of the key file “journaldev.pem” from your local machine. That’s it. Click on the “Launch SSH Client” and you are done.

Terminate EC2 Instance

You can terminate the EC2 instance at any point in time. Click on the “Actions > Instance State”, you will see the last option in the dropdown “Terminate”.

Step 13 Terminate Instance

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages