What Happens When EC2 Stops or Hibernates a Spot Instance?

When Amazon EC2 reclaims a Spot Instance configured to stop or hibernate rather than terminate, your underlying storage volumes and instance state are preserved until spare compute capacity becomes available again. By default, Spot Instances are terminated when AWS needs the capacity back, which permanently deletes the instance and its ephemeral state. Changing the interruption behavior to stop or hibernate allows stateful workloads, databases, and in-memory applications to survive capacity interruptions and automatically resume once EC2 fulfills the persistent Spot request.

Understanding Spot Instance Interruption Behaviors

Amazon EC2 Spot Instances allow you to bid on spare AWS compute capacity at steep discounts compared to On-Demand pricing. Because AWS can reclaim this capacity at any time, every Spot Instance has an Configurable Interruption Behavior setting. You must configure a persistent Spot request to use the stop or hibernate options, as one-time Spot requests only support termination.

The three available interruption behaviors are:

  • Terminate (Default): EC2 sends a two-minute warning, shuts down the operating system, deletes the instance, and closes the Spot request (unless managed by a Spot Fleet or Auto Scaling group).
  • Stop: EC2 sends a two-minute warning, performs a standard operating system shutdown, and places the instance in a stopped state while keeping the root Amazon EBS volume attached.
  • Hibernate: EC2 triggers an immediate hibernation sequence, saving the contents of the instance's RAM to the root Amazon EBS volume before shutting down the underlying virtual machine.

What Happens When Interruption Behavior is Set to Stop

When your Spot Instance is configured to Stop on interruption and EC2 needs to reclaim the capacity, the following sequence of events occurs:

  1. Two-Minute Interruption Notice: EC2 publishes an interruption notice to the Instance Metadata Service (IMDS) and Amazon EventBridge two minutes before reclaiming the instance.
  2. Operating System Shutdown: At the end of the two-minute window, EC2 sends an ACPI shutdown signal to the guest operating system, halting running processes and unmounting file systems cleanly.
  3. State Transition and Storage Preservation: The instance transitions to the stopped state. The contents of RAM (in-memory data) are lost, as with any standard reboot or stop action. However, the root EBS volume and any attached secondary EBS volumes are preserved alongside your instance ID, private IP addresses, and network interface configurations.
  4. Billing Adjustments: While the instance is stopped, you are not charged for EC2 compute usage. You continue to pay standard rates for the provisioned EBS storage volumes and any Elastic IP addresses associated with the stopped instance.
  5. Automatic Restart: Because stopping an instance requires a persistent Spot request, the request remains in an open state. As soon as spare Spot capacity becomes available in that Availability Zone at or below your maximum price, EC2 automatically starts the instance. It boots from the root volume just like a newly started machine.

What Happens When Interruption Behavior is Set to Hibernate

When your Spot Instance is configured to Hibernate on interruption, the goal is to preserve both the persistent disk storage and the active in-memory state of your applications:

  1. Immediate Hibernation Trigger: Unlike the terminate and stop behaviors, a hibernating Spot Instance does not wait for a two-minute warning period before acting. As soon as EC2 decides to reclaim the instance, it immediately signals the operating system to begin hibernation. You still receive an EventBridge notification, but the hibernation starts right away to ensure the RAM dump completes before capacity is forcibly revoked.
  2. Saving RAM to EBS: The guest operating system freezes all running threads and writes the entire contents of the instance memory (RAM) to a swap file or partition on the root Amazon EBS volume. If an instance has \(R\text{ GiB}\) of RAM, the root volume must have at least \(R\text{ GiB}\) of free, contiguous space allocated for hibernation.
  3. Shutdown and Storage Preservation: Once the memory dump finishes, the virtual machine powers down and enters the stopped state. Any ephemeral instance store volumes are lost, but all EBS volumes, network interfaces, and security attributes remain intact.
  4. Billing Adjustments: Just like a stopped instance, you pay $0 for compute while the instance is hibernated, though you continue to pay for the EBS volumes (which are now slightly larger to accommodate the RAM allocation).
  5. Automatic Resume: When Spot capacity returns, EC2 restarts the instance. During boot, the kernel reads the saved memory image from the root EBS volume back into RAM and unfreezes the processes. Your applications resume execution from the exact millisecond they were interrupted, without needing to reload caches or re-initialize services.

Comparing Stop vs. Hibernate vs. Terminate

Feature Terminate Stop Hibernate
Spot Request Type One-time or Persistent Persistent only Persistent only
2-Minute Warning Grace Period Yes Yes No (Hibernates immediately)
Root EBS Volume Preserved Optional (DeleteOnTermination) Yes (Required) Yes (Required & Encrypted)
RAM (In-Memory State) Saved No No Yes
Private IP & Instance ID Kept No Yes Yes
Compute Charges When Offline None None None
EBS Storage Charges When Offline None (if deleted) Standard EBS rates Standard EBS rates

Prerequisites and Limitations for Stop and Hibernate

You cannot enable stop or hibernate on every EC2 instance configuration. AWS enforces strict technical requirements, particularly for hibernation:

  • EBS-Backed Instances Only: Both stop and hibernate require an Amazon EBSvolume as the root device. Instances backed by ephemeral Instance Store volumes only support termination.
  • Encryption Requirement for Hibernation: To use hibernate, the root EBS volume must be encrypted to protect sensitive in-memory data when it is written to disk.
  • Root Volume Size: For hibernation, the root EBS volume must be large enough to store the operating system, applications, and the entire RAM dump. The total required root storage \(S_{\text{total}}\) can be expressed as: \[S_{\text{total}} \ge S_{\text{OS}} + S_{\text{apps}} + R_{\text{RAM}}\]
  • Supported Instance Families and RAM Limits: Hibernation is only supported on specific C, I, M, R, and T instance families, and generally requires the instance to have less than \(150\text{ GiB}\) of RAM (for Linux) or \(16\text{ GiB}\) to \(64\text{ GiB}\) of RAM (for Windows), as larger memory footprints take too long to flush to disk during an interruption.
  • AMI Support: The Amazon Machine Image (AMI) must have the ec2-hibinit-agent (or hibinit-agent) installed and configured to allocate the necessary swap space upon first boot.
  • Manual Termination While Stopped: If you no longer need a stopped or hibernated Spot Instance, you must both cancel the persistent Spot request and terminate the stopped instance; canceling the request alone will leave the stopped instance and its EBS volumes accruing storage charges.