EC2 Hibernate
Stopping an instance while keeping its memory, so it resumes in seconds with apps and caches still warm.
What it is
When an instance is stopped, its EBS disks are kept but its memory (RAM) is lost. When it starts again the operating system boots from scratch, then the applications start and fill their caches, which can take minutes. When it is terminated, the root volume is normally deleted as well.
Hibernation is a third option: the instance stops, but the contents of its RAM are saved first. On the next start the RAM is restored and every process carries on where it left off. The operating system isn't restarted, so the instance is ready much faster.
How it works
- Running: applications and their data are in RAM.
- Hibernate: EC2 tells the operating system to suspend to disk. It freezes all processes and writes the RAM contents to a file on the root EBS volume, then shuts down.
- Stopped: the instance itself costs nothing, only for the EBS storage (which now includes the saved RAM). The public IPv4 address is released; private IPs and Elastic IPs stay.
- Start: the instance boots, reads the RAM back from the root volume and unfreezes the processes. Applications resume with warm caches.
Use cases:
- long-running processes that need to pause and resume;
- saving the in-memory state of a job;
- services that take a long time to initialise, which can be pre-warmed once and then hibernated until needed.
Requirements
- Enable it at launch. Hibernation can't be turned on for an existing instance.
- Root volume: must be EBS (not instance store), encrypted, and large enough to hold the RAM plus the OS and apps. Supported volume types are gp2, gp3, io1 and io2.
- RAM: under 150 GiB for Linux, 16 GiB or less for Windows.
- Instance families: most current general purpose, compute, memory and storage optimized families (for example M, C, R, I and T types). Bare metal instances aren't supported.
- AMIs: Amazon Linux 2023, Amazon Linux 2, Ubuntu, RHEL and Windows Server, among others.
- Purchase options: On-Demand (with or without RIs or Savings Plans) and Spot. For Spot, the request must be persistent.
- Duration: an instance can stay hibernated for at most 60 days. To keep it longer, start it, stop it, and start it again.
- Not in an Auto Scaling group or ECS: Auto Scaling would mark the stopped instance unhealthy and replace it.
Updated since the slides
The slides list only a few families (C3–C5, I3, M3–M4, R3–R4, T2, T3) and a single 150 GB limit. Hibernation now supports most current families, including Graviton types, and the RAM limit for Windows is 16 GiB.
Exam tips
- "Keep the in-memory state", "faster boot", "applications take a long time to warm up" → EC2 Hibernate.
- "Root volume must be…" → EBS, encrypted, big enough for RAM.
- Limits: RAM under 150 GiB (Linux), at most 60 days hibernated, enable at launch.
Common traps
- "Hibernate an instance that's already running without hibernation enabled." It must be enabled at launch.
- "Hibernate with an instance store root volume." Instance store data is lost on stop; the root must be EBS.
- "Hibernate instances in an Auto Scaling group to save money." Not supported.
Hands-on lab: hibernate and resume
Goal: prove that the RAM, and the uptime counter, survive hibernation.
Costs money
One t3.micro with a public IP, about $0.02 an hour while running. While hibernated you pay only for the 8 GB volume.
Launch with hibernation on
Launch instances: name saa-hibernate, tag Project=saa-lab, Amazon Linux 2023, t3.micro, key pair saa-lab-key, security group saa-web-sg. Under Configure storage → Advanced, set the root volume's Encrypted to Encrypted (default key). Under Advanced details, set Stop - Hibernate behavior to Enable. Launch.
Check the uptime
Connect with EC2 Instance Connect and run uptime. Note how long it has been up.
Hibernate
In the console choose Instance state → Hibernate instance. Wait until it's Stopped.
Start and compare
Start the instance, connect again and run uptime. The uptime continues from before (plus a little), instead of starting near zero: the OS never rebooted.
Expected result: after hibernate and start, uptime shows the original boot time, which proves the memory was restored.
Clean up: terminate saa-hibernate.