AWS EC2 Essentials: Deploy, Manage, and Optimize


AWS EC2 (Elastic Compute Cloud)

AWS EC2 (Elastic Compute Cloud) is one of the most fundamental services in AWS. It provides scalable computing power in the cloud, allowing you to launch virtual machines (instances) on demand.


1. What is AWS EC2?

Amazon EC2 is a web service that provides secure, resizable compute capacity in the cloud. It allows users to:

  • Run applications on virtual machines.
  • Scale compute resources up or down as needed.
  • Choose from various instance types optimized for different workloads.


2. EC2 Components

Instances

An instance is a virtual machine running on AWS. It consists of:

  • AMI (Amazon Machine Image) – The OS and software package.
  • Instance Type – Defines CPU, memory, storage, and network capacity.
  • EBS (Elastic Block Store) – Persistent storage for instances.
  • Security Group – Firewall rules for inbound and outbound traffic.
  • Key Pair – SSH keys for authentication.
  • Elastic IP (optional) – Static IP address for instances.


3. EC2 Pricing Models

  1. On-Demand Instances – Pay per second/minute without long-term commitments.
  2. Reserved Instances – Commit to 1-3 years for discounted pricing.
  3. Spot Instances – Purchase unused capacity at lower rates (ideal for batch jobs).
  4. Dedicated Hosts – Physical servers dedicated to your use.
  5. Savings Plans – Flexible pricing based on long-term commitment.


4. EC2 Instance Types

Amazon EC2 instance types are designed to suit various workload needs:

  • General Purpose (T, M): Offer a balanced mix of compute, memory, and networking, suitable for everyday applications.
  • Compute Optimized (C): Provide high-performance processing for compute-intensive tasks.
  • Memory Optimized (R, X): Deliver large memory capacities for memory-bound applications like in-memory databases.
  • Accelerated Computing (P, G, F): Feature GPUs and FPGAs for machine learning, graphics rendering, and specialized computing.
  • Storage Optimized (I, D): Designed for high throughput and low latency, ideal for data-intensive workloads.


5. How to Create an EC2 Instance

A. Using AWS Console

  1. Go to EC2 Dashboard → Click Launch Instance.
  2. Choose an AMI (Amazon Machine Image).
  3. Select Instance Type (e.g., t2.micro for free tier).
  4. Configure Instance Details: Number of instances VPC and subnet IAM role
  5. Add Storage (EBS volume).
  6. Configure Security Group (Firewall rules).
  7. Create or Select Key Pair (For SSH access).
  8. Launch Instance.

B. Using AWS CLI

aws ec2 run-instances --image-id ami-12345678 --count 1 --instance-type t2.micro --key-name MyKey --security-groups MySecurityGroup
        

6. EC2 Storage - EBS vs Instance Store

A. Block Storage

Amazon Elastic Block Store (EBS)

  • Persistent Storage: EBS volumes are durable, network-attached block storage devices that persist independently of the lifecycle of an EC2 instance. They’re ideal for data that requires long-term storage.
  • Volume Types:
  • Snapshots & Backup: You can take point-in-time snapshots of EBS volumes, which are stored in Amazon S3 for backup and disaster recovery.


B. Instance Storage (Ephemeral Storage)

  • Direct-Attached Storage: Instance store volumes are physically attached to the host machine that runs your EC2 instance, offering very high IOPS.
  • Ephemeral Nature: Data on instance stores is temporary—it is lost when the instance is stopped, terminated, or if the underlying hardware fails. They’re best used for caches, buffers, or temporary data.

7. EC2 Networking - Security & Connectivity

A. Security Groups

Security Groups act as firewalls for EC2 instances, allowing or blocking traffic.

  • Inbound Rules – Define incoming traffic.
  • Outbound Rules – Define outgoing traffic.

Example: Allow SSH & HTTP access:

aws ec2 authorize-security-group-ingress --group-id sg-12345678 --protocol tcp --port 22 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id sg-12345678 --protocol tcp --port 80 --cidr 0.0.0.0/0
        

B. Elastic IPs

Elastic IPs are static public IPs assigned to an EC2 instance.

Allocate an Elastic IP:

aws ec2 allocate-address
        

Associate it with an instance:

aws ec2 associate-address --instance-id i-12345678 --public-ip 203.0.113.25
        

8. EC2 Load Balancing & Auto Scaling

A. Elastic Load Balancer (ELB)

Distributes incoming traffic across multiple EC2 instances.

To create a load balancer:

aws elb create-load-balancer --load-balancer-name my-load-balancer --listeners Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80 --availability-zones us-east-1a us-east-1b
        

B. Auto Scaling

Auto Scaling automatically adjusts the number of EC2 instances based on demand.

Create an Auto Scaling group:

aws autoscaling create-auto-scaling-group --auto-scaling-group-name my-asg --launch-configuration-name my-launch-config --min-size 1 --max-size 3 --desired-capacity 2 --availability-zones us-east-1a us-east-1b
        

9. EC2 Monitoring & Logging

AWS provides monitoring tools:

  • CloudWatch – Monitor instance metrics like CPU, memory, and network.
  • CloudTrail – Track API activity and security auditing.
  • AWS Systems Manager – Manage instances at scale.



To view or add a comment, sign in

More articles by Venkatavelavan N.

Insights from the community

Others also viewed

Explore topics