An EC2 instance is not simply "on or off": it goes through several states during its lifetime, and each has important consequences, especially on your bill. Confusing "stop" with "terminate" is one of the mistakes that most often surprises beginners. Let's clarify this once and for all.

The states of an instance

These are the states an instance goes through:

State What it means Do you pay?
pending Starting up, not ready yet No (not yet)
running On and working Yes (compute + storage)
stopping Shutting down Transition
stopped Off, like a powered-off PC Only the disk (not compute)
terminated Deleted forever No (but it's lost)

Let's look at the three states that really matter: running, stopped, and terminated.

Running: on and charging

When the instance is running, it is working and you pay for it: you pay for compute (per second or per hour depending on the type) and the associated storage.

This is the normal working state. Here is where your server serves your website, runs your application, etc.

Stopped: off (like shutting down your PC)

Stopping (stop) an instance is like shutting down your home computer:

  • The operating system shuts down.
  • You stop paying for compute (the "processor rental").
  • You keep paying for the disk (the EBS storage, which we'll see shortly), because your data is still stored.
  • You can start it up again whenever you want and your data will still be there.

Real example: You have a test server that you only use during office hours. You stop it at night and on weekends. This way you stop paying for compute when you're not using it, but keep all your work. When Monday comes, you start it up and it's just as you left it. This can save more than 60% of compute costs.

An important detail when stopping: some things may change when you start it up again, such as the public IP (it may be different). To avoid this, use Elastic IPs, which we'll see in subchapter 4.4.

Terminated: deleted forever ⚠️

Terminating (terminate) an instance is to destroy it completely:

  • The instance disappears.
  • By default, its main disk is deleted and you lose all data that was on it.
  • It cannot be undone. There is no recycle bin.

⚠️ Warning: "Stop" and "terminate" sound similar but are radically different. Stop = shut down (recoverable). Terminate = destroy (irreversible). Many newcomers terminate an instance thinking they were just shutting it down and lose their work. Read carefully before clicking.

When to terminate on purpose? When you no longer need the instance and want to stop paying for everything (compute and disk). This is the right thing to do to clean up test resources and avoid accumulating costs.

Storage: EBS and data persistence

To really understand the lifecycle, you need to know where the data lives. An instance's disk is usually an EBS (Elastic Block Store) volume: a virtual hard drive attached to the instance.

The key is an option called "delete on termination":

  • Enabled (default for the root disk): when the instance is terminated, the disk is deleted. Data lost.
  • Disabled: the disk survives the termination of the instance and you can reuse or recover its data.

Best practice: For important data, don't rely solely on the instance's disk. Make snapshots (backups) of your EBS volumes regularly. A snapshot is a picture of the disk stored safely, from which you can restore. We'll see centralized backups in Chapter 26 (AWS Backup).

Visual summary of the cycle

   Launch
     │
     ▼
 [pending] → [running] ⇄ [stopped]   ← stop/start as many times as you want
                │            │           (data preserved)
                │            │
                └────────────┴──→ [terminated]   ← END: instance destroyed
                                                   (root disk data deleted)

Cost implications (the essentials)

Action Pay for compute Pay for disk Keep data
running Yes Yes Yes
stopped No Yes Yes
terminated No No No

The big cost lesson: if you’re not using an instance temporarily, stop it (save compute). If you no longer need it, terminate it (save everything). Don’t leave unused running instances: it’s the number one cause of surprise bills.

What you should remember

  • The key states are running (on, you pay for everything), stopped (off, you only pay for disk, data is safe), and terminated (destroyed, irreversible, root disk data deleted).
  • Stop ≠ Terminate. Stop is recoverable; terminate is final. Read carefully before acting.
  • EBS storage persists data; watch the "delete on termination" option and make snapshots of important things.
  • To control costs: stop what you’re not using now, terminate what you no longer need.

In the next subchapter, we’ll see how to give your instances a fixed IP address (Elastic IP) and how to physically group them with Placement Groups.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved