Amazon EC2 basics — instances, Auto Scaling and load balancing
Amazon Elastic Compute Cloud (Amazon EC2) gives you virtual servers, called instances, that you can start in minutes, resize, and stop when you no longer need them. It is the classic “infrastructure as a service”: AWS runs the hardware, and you control everything from the operating system up.
What you choose when you launch an instance
| Part | What it is | Example |
|---|---|---|
| AMI (Amazon Machine Image) | The template the instance starts from: operating system plus any preinstalled software | Amazon Linux, Ubuntu, Windows Server, or your own image |
| Instance type | The amount of CPU, memory, storage and network performance | t3.micro for a small test site, r7g.2xlarge for a large database |
| Storage | Usually an Amazon EBS volume as the root disk | A 30 GB general purpose volume |
| Network | Which VPC and subnet the instance runs in | A public subnet for a web server |
| Security group | A virtual firewall listing which traffic may reach the instance | Allow HTTPS (port 443) from anywhere |
| Key pair | Keys used to sign in securely | Used with SSH for Linux |
An instance can be running, stopped (you keep the EBS disk but stop paying for compute) or terminated (deleted). You pay for compute only while it runs.
Instance type families
Instance type names follow a pattern. In m7g.large, m is the family, 7 the generation, g an extra attribute (here, an AWS Graviton processor), and large the size.
| Family | Best for | Letters you will see |
|---|---|---|
| General purpose | A balance of CPU, memory and network: web servers, small databases, development | M, T |
| Compute optimized | CPU-heavy work: batch processing, video encoding, game servers, scientific modeling | C |
| Memory optimized | Large data sets in memory: in-memory databases, real-time big data analysis | R, X |
| Storage optimized | Very high, fast reads and writes to local storage: data warehousing, large transactional databases | I, D |
| Accelerated computing | GPUs and other accelerators: machine learning, graphics, video processing | P, G, Inf, Trn |
Making EC2 elastic: Auto Scaling and load balancing
One server is a single point of failure and has fixed capacity. Two services fix that.
Amazon EC2 Auto Scaling
An Auto Scaling group keeps the right number of instances running:
- You set a minimum, a maximum and a desired number of instances.
- Scaling policies add instances when demand rises (for example, when average CPU goes above 60%) and remove them when it falls.
- If an instance fails a health check, Auto Scaling replaces it automatically.
This is how elasticity works in practice: capacity follows demand, so you neither run out nor pay for idle servers.
Elastic Load Balancing (ELB)
A load balancer is a single entry point that spreads incoming traffic across many instances, in multiple Availability Zones, and sends traffic only to healthy ones.
| Type | Works with | Typical use |
|---|---|---|
| Application Load Balancer | HTTP and HTTPS requests; can route by URL path or host name | Websites, web APIs, microservices |
| Network Load Balancer | TCP and UDP connections, very high performance | Gaming, real-time streaming, very high traffic |
| Gateway Load Balancer | Third-party network appliances | Firewalls and inspection tools |
Together: the load balancer spreads users across instances, and Auto Scaling changes how many instances there are.
Who manages what
EC2 gives you the most control, so you also have the most responsibility: you patch the guest operating system, install and update software, and configure security groups. If you would rather not manage servers, look at containers on AWS Fargate or functions on AWS Lambda, covered in containers and serverless compute.
Putting it together: a news website
A news site runs on EC2.
- It uses general purpose
m-family instances from an AMI with its web software installed. - An Application Load Balancer receives all visitors and spreads them across instances in two Availability Zones.
- An Auto Scaling group keeps at least two instances running, and adds up to ten when a big story breaks.
- If an instance crashes, Auto Scaling replaces it, and the load balancer stops sending traffic to it in the meantime.
Common mix-ups
- Stop vs terminate. A stopped instance can be started again and keeps its EBS volume; a terminated instance is gone.
- Auto Scaling vs load balancing. Auto Scaling changes the number of instances; a load balancer spreads traffic across them.
- Instance family names. Compute optimized is for CPU-heavy work; memory optimized is for large in-memory data; storage optimized is for very fast local disk access.
Check yourself
Which instance family suits a high-performance video encoding job that is mostly CPU-bound?
Compute optimized (C family).
What provides elasticity for a fleet of EC2 instances?
Amazon EC2 Auto Scaling, which adds and removes instances as demand changes.
What does a load balancer do when one instance becomes unhealthy?
It stops sending traffic to that instance and spreads requests across the healthy ones.
Who patches the operating system of an EC2 instance?
The customer.
Exam tip for Cloud Practitioner
EC2 is infrastructure as a service: you control the OS, so you patch it. “Automatically add and remove servers” is Auto Scaling. “Distribute traffic across instances in multiple AZs” is Elastic Load Balancing. Match the workload to the family: CPU-heavy → compute optimized, in-memory → memory optimized, fast local storage → storage optimized, GPUs → accelerated computing.
Key takeaways
- EC2 instances are virtual servers built from an AMI and an instance type.
- Five instance families: general purpose, compute, memory, storage optimized, accelerated computing.
- Auto Scaling changes how many instances run; Elastic Load Balancing spreads traffic across them.
Cloud Study Lab is an independent study site. It is not affiliated with or endorsed by Amazon Web Services. AWS and the names of AWS certifications are trademarks of Amazon.com, Inc. or its affiliates.