EC2 is one of the most popular of AWS’ offering and provides tons of features to fully leverage cloud computing according to our need. It is an abbreviation of Elastic Compute Cloud. It is an on-demand re-sizable compute service provided by Amazon in the cloud. It includes all the services a computing device can offer along with the flexibility of a virtual environment.
It’s not just a single service, instead composed of many things:
- It can provide/rent virtual machines of customer’s choice.
- Provision to attach storage.
- Allow us to distribute load across many different machines using Elastic Load Balancing
- We can scale instances as per requirement using Auto Scaling Group
EC2 Instance
EC2 Instances are the virtual servers that we can take from AWS to run applications on the cost of paying rent for them. An instance has its own hardware drive, operating system, network connection etc. but everything is virtual. There can be multiple instances on a single physical computer. Even the user can dismantle the virtual device once its task is completed or if it’s not required anymore. For providing all these scalable resources AWS charges some bill amount at the end of every month, bill amount is entirely dependent on our usage. We can do the following configuration for our rented server:
- Choose Operating System – Linux, Windows, Mac
- How much Compute power or CPU
- How much RAM
- Handle Firewall Rules using Security group
- Bootstrap script to configure the instance at first launch
Benefits and Features of EC2 Instances
Users can configure their instances as per their requirements i.e. allocate the RAM, ROM, and storage as per need. We can select different hardware and software configurations. It provides redundancy in case of any failures. It allows organizations to develop and deploy applications much faster, without any upfront investment for the hardware.
Some of the prominent features of EC2 −
Reliable − Amazon EC2 offers a highly reliable environment where replacement of dead instances is instantly possible. It provides facility to scale up and scale down as per need.
Designed for Amazon Web Services − Amazon EC2 works perfect with Amazon services like Amazon S3, Amazon RDS, Amazon DynamoDB, and Amazon SQS. It provides a full solution for compute and storage across a wide range of applications.
Secure − Amazon EC2 works in Amazon Virtual Private Cloud to provide a secure network to resources. We can configure security group to secure our instances. Also, IAM roles can be used to provide security.
Inexpensive − Amazon EC2 is based on pay per use strategy i.e. we will only be billed for what we actually use. It offers multiple purchase plans which we can choose as per our requirement.
Set up an EC2 Instance
We have to first Login into our AWS account and on the management console, click on AWS EC2. Under create instance, click on launch instance and need to follow the below steps:-
1) Choose AMI
An AMI is a template that is used to create a new instance or virtual machine. It will contain information about the software, operating system, volume, and access permissions.
Types of AMIs:
i) Predefined AMIs: Created by Amazon itself.
ii) Custom AMIs: The user creates these, and they can be reused. These AMIs are also available in the AMI Marketplace
2) Choose instance type
An instance type specifies the hardware specifications that are required in the machine
Instance types belong to five main families:
i) Compute-optimized– For situations that require a lot of processing power from CPU. They are designed to run data-intensive applications that require faster network performance and high input output operations per second. For example, applications including machine learning.
ii) Memory-optimized– For applications that are heavy, hence require larger Random Access memory and lesser cpu power. We can use these instance types when we want many applications to run in background.
iii) GPU optimized– For setting up a gaming system, or something with the requirement of a large graphic rendering
iv) Storage optimized– For applications that are larger in size and occupies lot of space. Well suited for applications that require high I/O performance, such as NoSQL databases that store and retrieve data in real time.
v) General-purpose– These instance types are mainly used when everything is equally balanced (performance and cost). They are designed to handle a variety of workloads. Some common use cases include software development and testing.
3) Configure Instance:
You have to specify the number of instances, purchasing options, the kind of network, the subnet, assign a public IP, set the IAM role etc.
In the advanced details, we can write bootstrap scripts that are executed when the VM starts up. It also offers multiple payment options, such as:
i) On-demand instances– They can be launched whenever the user requires it and available with normal rates.
ii) Reserved instances– These instances are reserved for one year or three years. The entire amount has to be paid in advance or over a span of a few months.
iii) Spot instances– These instances are provided on the basis of bidding process. Bidding goes to the customer with the highest bid. They are less expensive than on-demand instances.
4) Adding Storage:
Deciding the type of storage, which could be:
i) Ephemeral Storage – A temporary and free storage attached to our instance, which is only present when our instance is in running state.
ii) Amazon Elastic Block Store – A Block storage based service. Data stored in EBS volume is paid and retained permanently.
iii) Amazon S3 – An Object based paid storage service.
5) Adding tags:
This helps to identify instances more quickly. Type a name for your AWS EC2 instance in the value box. This name, more correctly known as tag, will appear in the console when the instance launches. It makes it easy to keep track of running instances in a complex environment. We should use a name that can be easily recognized and remembered.
6) Configuring security groups:
These are a kind of firewall rules based on which users are given access to the EC2 instance. We can set up the type of protocol, the port range, and source (from where the incoming traffic is coming from). Incoming traffic has to be explicitly defined, and outgoing traffic is open.
7) Key Pair:
A Key pair is a kind of security credentials that user uses to prove his identity while connecting to the instance.
Private key: This key is downloaded by user to log-in to the instances.
Public key: This key is used by AWS to confirm the identity of the user.
After choosing ‘create a new pair’, a new private key is generated and downloaded as a .pem file.
Anyone who is having our private key can access our instance, so its mandatory to store it securely somewhere.
Instance Lifecycle
An instance lifecycle starts when it is launched and ends when it is finally terminated.
Initially, when you launch a new EC2 instance from an AMI image, it enters in the pending state. The instance type that you specified at launching time, determines the hardware characteristics of the host computer for your EC2 instance. When your EC2 instance is in the pending state, AWS move the EC2 instance into a new host computer.
When we stop the EC2 instance, it performs a normal shutdown and then transitions to a stopped state. While our instance is in the stopped state, we could modify some instance’s attributes like the instance type etc. After stopping, AWS doesn’t charge users for the instance, but it do charge for any attached Amazon EBS volumes related usage.
Finally, when an EC2 instance is terminated, the instance performs a normal shutdown. All host resources are liberated, and the root device volume is deleted by default.
Connecting with your EC2 instance
Connecting with our newly created instance is quite straightforward. We can connect to the instance over a private network using an SSH client or the EC2 Instance Connect CLI.
Steps to connect:
1) Open your Amazon EC2 Console
2) Choose the instance you want to connect
3) Click “Connect”
We are connected to our instance. Let’s start with a quick demo to play with it now.
Links
Amazon EC2 instances – Amazon Elastic Compute Cloud
https://www.geeksforgeeks.org/what-is-elastic-compute-cloud-ec2
What is AWS EC2: Learn Elastic Compute Cloud (EC2) in AWS (edureka.co)