EC2 Compute

💤0
Lv 10 XP
← 🟧 Amazon Web Services · Core Services

EC2 Compute

Intermediate ⭐ 80 XP ⏱ 18 min #aws#ec2#compute

Launch and secure virtual servers, and scale them with Auto Scaling groups.

📖Theory

EC2 provides resizable virtual servers (instances). Launching one means choosing an AMI (image), an instance type (family + size, e.g. t3.micro), a key pair for SSH, security groups (stateful firewall), and storage (EBS volumes).

For elasticity, an Auto Scaling Group (ASG) keeps a target number of instances healthy across AZs and scales on metrics, usually behind an Elastic Load Balancer. User data scripts bootstrap an instance at first boot.

🌍Real-World Example
aws ec2 run-instances \
  --image-id ami-0abcd1234 \
  --instance-type t3.micro \
  --key-name my-key \
  --security-group-ids sg-0123 \
  --user-data file://bootstrap.sh

# Auto Scaling: maintain 2–6 instances behind a load balancer
aws autoscaling create-auto-scaling-group \
  --auto-scaling-group-name web-asg \
  --min-size 2 --max-size 6 --desired-capacity 2 \
  --vpc-zone-identifier "subnet-a,subnet-b"
✍️Hands-On Exercise
  1. List the components you must choose to launch an EC2 instance.
  2. Write an SG rule (in words) allowing SSH only from your office IP.
  3. Explain how an Auto Scaling Group improves availability and cost.
  4. Describe what a user-data script is used for.
🧾Cheat Sheet
ComponentRole
AMIMachine image (OS + software)
Instance typeCPU/memory family + size
Key pairSSH access
Security groupStateful instance firewall
EBSPersistent block storage
Auto Scaling GroupMaintain/scale instances
User dataFirst-boot bootstrap script
💬Common Interview Questions
What is an Auto Scaling Group?

A service that maintains a desired number of EC2 instances across AZs, replacing unhealthy ones and scaling in/out on metrics or schedules — usually behind a load balancer for elasticity and resilience.

Are EC2 security groups stateful or stateless?

Stateful — if you allow an inbound flow, the return traffic is automatically allowed. They contain only allow rules and attach to instance network interfaces.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type