EC2 Stop vs. Terminate: What Actually Happens to Your EBS Data
You stopped your EC2 instance to cut costs over the weekend — but now you're second-guessing yourself: did you just risk losing everything on that volume? Understanding the precise difference between Stop and Terminate is one of the most operationally critical distinctions in AWS, and getting it wrong can mean permanent, unrecoverable data loss.
TL;DR
| Dimension | Stop | Terminate |
|---|---|---|
| Instance State | Stopped (restartable) | Terminated (permanent) |
| EC2 Billing | No instance-hour charges while stopped | No instance-hour charges after termination |
| Root EBS Volume | Persists, remains attached | Deleted by default (configurable) |
| Additional EBS Volumes | Persist, remain attached | Persist by default (configurable) |
| Instance Store (ephemeral) | Data is lost on stop | Data is lost on termination |
| Elastic IP | Retained (but billed if unassociated) | Disassociated from instance |
| Private IP | Retained | Released |
| Public IP (non-EIP) | Released on stop, new one on start | Released |
| RAM Contents | Lost (unless Hibernate is enabled) | Lost |
| Reversible? | Yes — Start the instance | No — Permanent action |
The Instance Lifecycle: A State Machine View
An EC2 instance is a state machine. Stop and Terminate are two distinct state transitions with very different downstream effects on attached resources. The diagram below maps the full lifecycle.
- pending → running: Instance boots; EBS root volume is attached and in-use.
- running → stopping → stopped: OS is shut down gracefully. The instance is frozen but all EBS volumes remain attached. No compute charges accrue.
- stopped → running: Instance restarts, potentially on different underlying hardware. EBS data is fully intact.
- running → shutting-down → terminated: A one-way door. By default, the root EBS volume is deleted. The instance record eventually disappears from the console.
- Any state → terminated: Force-termination is possible from most states.
Architecture: What Happens to Your Storage
The most consequential difference is storage behavior. The diagram below shows the fate of each storage type under both actions.
/dev/xvda"] Instance --> ExtraEBS["Additional EBS Volume
/dev/xvdb"] Instance --> InstStore["Instance Store
ephemeral0"] RootEBS --> StopRoot["STOP:
State: in-use
Data: Intact
Billed: Yes"] RootEBS --> TermRoot{"TERMINATE:
DeleteOnTermination?"} TermRoot -->|"true (default)"| TermRootDel["Volume DELETED
Data: Gone"] TermRoot -->|"false (configured)"| TermRootKeep["Volume survives
State: available"] ExtraEBS --> StopExtra["STOP:
State: in-use
Data: Intact
Billed: Yes"] ExtraEBS --> TermExtra{"TERMINATE:
DeleteOnTermination?"} TermExtra -->|"false (default)"| TermExtraKeep["Volume survives
State: available"] TermExtra -->|"true (configured)"| TermExtraDel["Volume DELETED
Data: Gone"] InstStore --> StopInst["STOP:
Data: PERMANENTLY LOST"] InstStore --> TermInst["TERMINATE:
Data: PERMANENTLY LOST"] style TermRootDel fill:#ff4d4d,color:#fff style TermExtraDel fill:#ff4d4d,color:#fff style StopInst fill:#ff4d4d,color:#fff style TermInst fill:#ff4d4d,color:#fff style TermRootKeep fill:#2ecc71,color:#fff style TermExtraKeep fill:#2ecc71,color:#fff style StopRoot fill:#3498db,color:#fff style StopExtra fill:#3498db,color:#fff
- On Stop: The EBS root volume and any additional EBS volumes remain attached to the (stopped) instance. Their state is
in-use. You continue to pay EBS storage costs. - On Stop (Instance Store): All data on instance store (ephemeral) volumes is immediately and permanently erased. This is a hardware-level wipe — there is no recovery path.
- On Terminate (Root EBS): The
DeleteOnTerminationflag governs this. It defaults totruefor root volumes — meaning the volume is deleted when the instance terminates. - On Terminate (Additional EBS): The
DeleteOnTerminationflag defaults tofalsefor non-root EBS volumes — they persist as available, unattached volumes after termination.
Analogy: Think of Stop like putting your laptop into sleep mode and locking it in a drawer. The hard drive is untouched; you just aren't paying for electricity. Terminate is like sending the laptop to a shredder — the hard drive (root volume) is destroyed by default, unless you specifically told the shredder to eject it first (DeleteOnTermination=false).
Deep Dive: EBS Volume Behavior
The DeleteOnTermination Flag
This attribute is set per-volume at instance launch and controls whether an EBS volume is deleted when its attached instance is terminated. It can be modified while the instance is running or stopped.
Check the current flag value via AWS CLI:
aws ec2 describe-instances \
--instance-ids i-0abcdef1234567890 \
--query "Reservations[].Instances[].BlockDeviceMappings[].{Device:DeviceName,DeleteOnTermination:Ebs.DeleteOnTermination}" \
--output table
Modify the flag on a running or stopped instance (protect your root volume):
aws ec2 modify-instance-attribute \
--instance-id i-0abcdef1234567890 \
--block-device-mappings '[{"DeviceName":"/dev/xvda","Ebs":{"DeleteOnTermination":false}}]'
Setting DeleteOnTermination=false on the root volume is a critical safety net for production instances. If the instance is accidentally terminated, the root volume survives as an unattached EBS volume that you can re-attach or snapshot.
EBS Costs While Stopped
Stopping an instance eliminates EC2 compute charges, but EBS volumes continue to accrue storage costs regardless of instance state. If cost elimination is the goal, you must snapshot the volume, delete it, and restore from the snapshot when needed. Pricing and limits vary — always check the official AWS documentation.
Hibernate: The Third Option
Standard Stop discards RAM contents. Hibernate is a special stop mode that saves the in-memory state (RAM) to the root EBS volume before shutting down, allowing the instance to resume exactly where it left off — open connections, running processes, and all.
| Behavior | Stop | Hibernate |
|---|---|---|
| RAM contents saved | No | Yes (written to root EBS) |
| Boot time on resume | Full OS boot | Near-instant resume |
| Root EBS requirement | Standard | Must be encrypted; must have enough free space for RAM dump |
| Instance type support | All EBS-backed | Specific instance families only |
Hibernate must be enabled at launch time — it cannot be enabled on an already-running instance.
Termination Protection: Your Last Line of Defense
AWS provides a Termination Protection flag that prevents accidental termination via the console, CLI, or API. It does not protect against termination triggered by Auto Scaling or Spot interruptions.
Enable termination protection:
aws ec2 modify-instance-attribute \
--instance-id i-0abcdef1234567890 \
--disable-api-termination
Verify the setting:
aws ec2 describe-instance-attribute \
--instance-id i-0abcdef1234567890 \
--attribute disableApiTermination
Decision Framework: Which Action Should You Take?
again in the future?"} Q1 -->|"No"| Q2{"Do you need to preserve
any EBS volumes?"} Q1 -->|"Yes"| Q3{"Do you need RAM state
preserved on resume?"} Q2 -->|"No"| Terminate["TERMINATE
Default flags apply"] Q2 -->|"Yes"| SetFlag["Set DeleteOnTermination=false
on volumes, then TERMINATE"] Q3 -->|"No"| Stop["STOP
Safe — EBS data intact"] Q3 -->|"Yes"| HibCheck{"Was Hibernate enabled
at launch?"} HibCheck -->|"Yes"| Hibernate["HIBERNATE
RAM saved to EBS"] HibCheck -->|"No"| Stop2["STOP (only option)
RAM contents will be lost"] style Terminate fill:#e74c3c,color:#fff style SetFlag fill:#e67e22,color:#fff style Stop fill:#2ecc71,color:#fff style Stop2 fill:#2ecc71,color:#fff style Hibernate fill:#3498db,color:#fff
Operational Checklist Before Terminating
🔽 [Click to expand] Pre-Termination Safety Checklist
- ✅ Snapshot all EBS volumes you want to preserve:
aws ec2 create-snapshot --volume-id vol-0abcdef1234567890 --description "Pre-termination backup" - ✅ Verify
DeleteOnTerminationflags for all attached volumes usingdescribe-instances. - ✅ Note your Elastic IP associations — EIPs are disassociated on termination but not released (you'll be billed for unassociated EIPs).
- ✅ Export any data from instance store volumes — this data is gone the moment the instance stops or terminates.
- ✅ Check for dependent resources — Load balancer target groups, Auto Scaling groups, or Route 53 health checks pointing to this instance.
- ✅ Deregister from load balancers if applicable to avoid 502/503 errors during the transition.
- ✅ Review IAM instance profile — document the role ARN (e.g.,
arn:aws:iam::123456789012:role/MyInstanceRole) for re-attachment to a replacement instance.
Glossary
| Term | Definition |
|---|---|
| EBS (Elastic Block Store) | Network-attached, persistent block storage for EC2. Data survives instance stop and (by configuration) termination. |
| Instance Store | Physically attached ephemeral storage on the host machine. Data is lost on stop, hibernate, or termination — no exceptions. |
| DeleteOnTermination | A per-volume EBS attribute that controls whether the volume is automatically deleted when its attached instance is terminated. |
| Termination Protection | An instance-level flag (DisableApiTermination) that blocks termination via the API, CLI, or console. |
| Hibernate | A stop mode that persists RAM contents to the encrypted root EBS volume, enabling fast resume without a full OS boot. |
Next Steps
- 📖 AWS Docs: EC2 Instance Lifecycle
- 📖 AWS Docs: Terminate Your Instance
- 📖 AWS Docs: Hibernate Your Instance
- 🔒 Immediate action: Audit your production instances now — run
describe-instancesand verifyDeleteOnTerminationandDisableApiTerminationsettings before an incident forces you to.
Comments
Post a Comment