EC2 Compute
Launch and secure virtual servers, and scale them with Auto Scaling groups.
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.
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" - List the components you must choose to launch an EC2 instance.
- Write an SG rule (in words) allowing SSH only from your office IP.
- Explain how an Auto Scaling Group improves availability and cost.
- Describe what a user-data script is used for.
Cheat Sheet▾
| Component | Role |
|---|---|
| AMI | Machine image (OS + software) |
| Instance type | CPU/memory family + size |
| Key pair | SSH access |
| Security group | Stateful instance firewall |
| EBS | Persistent block storage |
| Auto Scaling Group | Maintain/scale instances |
| User data | First-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.