Amazon Elastic Compute Cloud (Amazon EC2)

From Theory to Application: A Practical Guide to Amazon EC2

·

7 min read

Many businesses use the client-server model to deliver their products, resources or data to millions of users all around the world. And they need servers to power their applications. You need raw computing capacity to host your applications and provide the computing power that your business needs. Working with AWS, these servers are virtual and the servers you use to access the virtual servers are EC2.

It's much easier to get started with Amazon EC2 :

  • AWS built the data centers.

  • AWS secured the data centers.

  • AWS purchased the servers.

  • AWS installed the servers

  • The servers are online and ready to use.

AWS constantly runs a huge compute capacity and you can use any portion of that capacity when you need it. One just needs to request the EC2 instances you want and they will get launched and boot up. Once you're done using them, you can easily stop or terminate the instances.

How an amazon EC2 works : Launch -> Connect -> Use

EC2 runs on top of a physical host server which is managed by AWS. When you launch an EC2 instance, you need not take up the entire host machine for yourself. Instead, you share the host machine with other EC2 instances known as virtual machines. The hypervisor installed in the physical host machine is responsible for sharing the underlying hardware and other physical resources among the virtual machines and is managed by AWS. The hypervisor isolates the virtual machines from each other so that they work individually as they share resources from the host which means the EC2 instances are secure despite sharing resources.

EC2 provides great flexibility and control by allowing users to easily create, manage, and configure virtual servers (instances) as needed. When you provide an EC2 instance, you can also choose the operating system whether Windows or Linux. You also configure what software you want running on the instance. EC2 instances are also resizable. You might start with a small instance, realize the application you are running is starting to max out that server, and then you can give that instance more memory and more CPU and this is called vertically scaling an instance. You can also control the networking aspect of the EC2, whether you want it to be publicly or privately accessible and which requests are to be accepted.


Amazon EC2 instance types

AWS has different types of EC2 instances that you can spin up and deploy into your AWS environment which are optimized for different tasks. Instance types offer varying combinations of CPU, memory, storage, and networking capacity, and give you the flexibility to choose the appropriate mix of resources considering the specific needs of your workloads and applications.

The different types of instance families are:

  • General purpose

  • Compute optimized

  • Storage optimized

  • Memory optimized

  • Accelerated computing

General purpose instances

General purpose instances provide a balance of compute, memory, and networking resources. Suppose that you have an application in which the resource needs for compute, memory, and networking are roughly equivalent. You might consider running it on a general purpose instance because the application does not require optimization in any single resource area.

Compute optimized instances

Compute optimized instances are ideal for compute-intensive tasks which require high performance processors. compute optimized applications are ideal for high-performance web servers, compute-intensive applications servers, and dedicated gaming servers.

Storage optimized instances

Storage optimized instances are designed for workloads that require high, sequential read and write access to large datasets on local storage. Examples of workloads suitable for storage optimized instances include distributed file systems, data warehousing applications, and high-frequency online transaction processing (OLTP) systems. If you have an application that has a high IOPS requirement, a storage optimized instance can provide better performance over other instance types.

Memory optimized instances

Memory optimized instances are designed to deliver fast performance for workloads that process large datasets in memory. Suppose that you have a workload that requires large amounts of data to be preloaded before running an application. This scenario might be a high-performance database or a workload that involves performing real-time processing of a large amount of unstructured data. In these types of use cases, consider using a memory optimized instance. Memory optimized instances enable you to run workloads with high memory needs and receive great performance.

Accelerated computing instances

Accelerated computing instances use hardware accelerators, or coprocessors, to perform some functions more efficiently than is possible in software running on CPUs. In computing, a hardware accelerator is a component that can speed up data processing.


Scaling Amazon EC2

Scalability involves using only the resources you need in the beginning and designing your architecture to automatically change according to the customer's changing demand by scaling in or scaling out. By this, you only pay for what you use.

The AWS service that makes the scaling process happen automatically for Amazon EC2 instances is Amazon EC2 Auto Scaling.


Practically creating an EC2 instance

Create instances in an appropriate region based on the customer’s region.

Take care of security, latency and region while creating an instance.

If the region faces a short circuit or the region goes down or there are some reliability issues with the site, then the customer will face a downtime and your application will stop working. To avoid this problem, AWS set up more availability zones even within a region.

If you don’t want to run into issues, then you can make your application highly available by deploying your application in more than one availability zone.

Sign in to your AWS console. Now, search for EC2 and select the first available service - EC2 (Virtual Servers in the Cloud). Now, Under the resources section, click on Instances and then click on Launch Instances.

Firstly, provide the name of the instance (e.g., my-first-instance). After this, choose an appropriate Operating System (e.g., Ubuntu). After choosing the OS, you choose the version of OS you want.

Now, pick an appropriate Instance type. There are several Instance types that offer varying combinations of CPU, memory, storage, and networking capacity.

Key pair (login) helps us log in to the instance. By default when you create an instance, AWS does not provide you a password. The password authentication to an instance is disabled by default. The only way to log in to an instance is by using a key-value pair which is a combination of public-private keys that you use to log in to an instance. The instance has the public key and you will have the private key, using the private key we log in to the instance. Never share your public-private key with anyone. Create a new key pair and select a pem file to connect the local shell to the server shell. And a pem file will be downloaded (e.g., aws_login.pem)

Now, click on Launch instance and your instance will be created within just a few minutes.

Connect Windows to EC2 instance

Go to your instances section and select the instance you created. Now click on the Connect button and click on the option SSH client. Under that, find the command under the example and copy that command.

The command would look like this:

ssh -i "aws_login.pem" ubuntu@ec2-public_IP_address.compute-1.amazonaws.com

  • ssh -> connecting a secure shell

  • -i -> to provide the filename (or) file path of the pem file.

Now, open your Windows PowerShell in the folder where you've previously downloaded the pem file and paste the copied command. Once you click enter, the prompt will ask whether you're sure to continue connecting, you now type yes. And now you've successfully logged into your instance.

How to connect to EC2 instance from Windows using MobaXterm

Install MobaXterm in your Windows operating system. Extract the downloaded zip file.

Now, Go to the instance that you've created and copy the Public IP address.

On MobaXterm, go to the sessions section and under that, choose the SSH option. Provide the hostname as the IP address that you copied. Specify the username(e.g., here as Ubuntu).

Now, go to advanced SSH settings, select the private key option and open the previously downloaded pem file here.