AWS Offers various services and each service has its use cases.
EC2 — Compute Service
EBS — Storage Service
VPC — Network Service
CloudFront — CDN Service
EC2 ( Elastic Compute Cloud ) :
It’s a Virtual Machine in AWS Cloud., It provides scalable computing capacity, scalable means that based on the demand/load we can increase and decrease the capacity of the servers. Scaling can be horizontal Scaling — Increasing the count of servers with the same configuration, Vertical Scaling — Achieved by changing the instance's capacity.
Now we will compare EC2 with regular computer components :
AMI — Stands for Amazon Machine Image
AMI is a preconfigured package that contains OS and some basic software settings and software. We can launch an EC2 instance with these AMIs.
There are 3 types of AMI present such as Community AMI, Marketplace AMI, MyAMI
Community AMI: Contains only OS, free to use, EX — ubuntu AMI, Debian AMI, RHEL AMI
MarketPlace AMI: Contains OS with additional licensed software, need to pay, EX — Splunk, NGINX.
MyAMI: We can create our own AMI with our OS and preconfigured settings.
We can create AMI from the existing EC2 instance, we can also use HashiCorp Packer. AMIs are region specific, AMI IDs present in the Mumbai region might be different from the Singapore region.
Instance Types in EC2 :
We have different instance types in the EC2 such as General purpose, compute-optimized, memory-optimized, GPU-optimized, storage optimized
Storage in EC2 :
In EC2, storage is essential for running and booting the operating system. Similar to how a hard disk works in a traditional computer, EC2 uses Elastic Block Store (EBS) for this purpose, which is a type of block storage.
Whenever we create an EC2 instance, it comes with root storage where the operating system is installed. This root storage can either be:
Elastic Block Store (EBS):
A reliable and persistent block storage option.
Retains data even when the instance is stopped or restarted.
Instance Store Volume (ISV):
An ephemeral storage option tied to the underlying virtual machine.
Data is lost if the instance is stopped or restarted, as ISV uses temporary storage from the virtual machine hosting the EC2 instance.
Recommendation:
It is generally recommended to use EBS as the root storage for EC2 instances because it ensures data persistence and reliability, unlike ISV, which is suitable only for temporary or non-critical data.
Security Groups in EC2 :
A firewall is used as a network security system to prevent unauthorized access to/from a private network. Security Groups acts as a virtual firewall that controls traffic for one or more instances. Only allow what traffic is required.
Security groups are used for inbound and outbound traffic., inbound means which traffic is allowed to the server, and outbound means which traffic is allowed outside, for example, if we don’t open port 22 which is for SSH in the inbound rules no other machine/system can connect to the server., similarly MySQL runs on the port 3309 and only if we open this port in Security Group other systems can access this port. We can leverage this Security Group as a Firewall to our EC2 instance.
Purchasing Options in EC2 :
EC2 offers various purchasing options such as
On-Demand Instances
Reserved Instances
Spot Instances
IP Addressing in EC2 :
Every EC2 instance will have IP Address ., there are 3 types of IP such as Public IP, Private IP, and Elastic IP.
Public IP — EC2 can be launched with/without a public IP address, we use this public IP to talk to the server, so systems present outside the network can talk to the server using this public IP.
Private IP — By default every EC2 instance will have a private IP address, Private IP addresses allow instances to communicate as long as they are present in the same VPC.
Elastic IP — If we need to have a permanent public IP for the instance we need to attach Elastic IP to the instance, even if we stop and start the server the IP doesn’t change.
We can have a combination of —
Public IP + Private IP
Private IP only without public IP so outsiders cannot talk to it
Private IP + Elastic IP
So in summary EC2 is a Virtual Machine we can use this VM to run applications or Database server or webserver or any tool such as Jenkins / Nexus / Sonarqube.
We can create this EC2 in many ways — GUI , CLI , API , SDKs , and Developmental tools such as Terraform ( Cloud Agnostic ), Cloud Formation Template ( AWS Specific ).
That’s all about the EC2.