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:
2. EC2 Components
Instances
An instance is a virtual machine running on AWS. It consists of:
3. EC2 Pricing Models
4. EC2 Instance Types
Amazon EC2 instance types are designed to suit various workload needs:
5. How to Create an EC2 Instance
A. Using AWS Console
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)
Recommended by LinkedIn
B. Instance Storage (Ephemeral Storage)
7. EC2 Networking - Security & Connectivity
A. Security Groups
Security Groups act as firewalls for EC2 instances, allowing or blocking 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: