EC2 Hibernation

Amazon EC2 (Elastic Compute Cloud) Hibernation is a feature that allows you to pause and resume your EC2 instances, similar to hibernating a laptop. When an EC2 instance is hibernated, the in-memory state (RAM) is saved to the root EBS (Elastic Block Store) volume, and the instance is stopped. When you start the instance again, the in-memory state is restored, allowing you to continue from where you left off. This can be beneficial for long-running processes or for maintaining the instance's transient state.

Overview of hibernation

The following diagram shows a basic overview of the hibernation process.

When you hibernate a running instance, the following happens:

  • When you initiate hibernation, the instance moves to the stopping state. Amazon EC2 signals the operating system to perform hibernation (suspend-to-disk). The hibernation freezes all of the processes, saves the contents of the RAM to the EBS root volume, and then performs a regular shutdown.

  • After the shutdown is complete, the instance moves to the stopped state.

  • Any EBS volumes remain attached to the instance, and their data persists, including the saved contents of the RAM.

  • Any Amazon EC2 instance store volumes remain attached to the instance, but the data on the instance store volumes is lost.

  • In most cases, the instance is migrated to a new underlying host computer when it's started. This is also what happens when you stop and start an instance.

  • When you start the instance, the instance boots up and the operating system reads in the contents of the RAM from the EBS root volume, before unfreezing processes to resume its state.

  • The instance retains its private IPv4 addresses and any IPv6 addresses. When you start the instance, the instance continues to retain its private IPv4 addresses and any IPv6 addresses.

  • Amazon EC2 releases the public IPv4 address. When you start the instance, Amazon EC2 assigns a new public IPv4 address to the instance.

  • The instance retains its associated Elastic IP addresses. You're charged for any Elastic IP addresses that are associated with a hibernated instance.

For information about how hibernation differs from reboot, stop, and terminate, see Differences between reboot, stop, hibernate, and terminate.

Hibernation prerequisites

Limitations

  • When you hibernate an instance, the data on any instance store volumes is lost.

  • You can't hibernate an instance that has more than 150 GB of RAM.

  • If you create a snapshot or AMI from an instance that is hibernated or has hibernation enabled, you might not be able to connect to a new instance that is launched from the AMI or from an AMI that was created from the snapshot.

  • You can't change the instance type or size of an instance when hibernation is enabled.

  • You can't hibernate an instance that is in an Auto Scaling group or used by Amazon ECS. If your instance is in an Auto Scaling group and you try to hibernate it, the Amazon EC2 Auto Scaling service marks the stopped instance as unhealthy, and might terminate it and launch a replacement instance. For more information, see Health Checks for Auto Scaling Instances in the Amazon EC2 Auto Scaling User Guide.

  • You can't hibernate an instance that is configured to boot in UEFI mode.

  • If you hibernate an instance that was launched into a Capacity Reservation, the Capacity Reservation does not ensure that the hibernated instance can resume after you try to start it.

  • You can’t hibernate an instance that uses a kernel below 5.10 if Federal Information Processing Standard (FIPS) mode is enabled.

  • AWS does not support keeping an instance hibernated for more than 60 days. To keep the instance for longer than 60 days, you must start the hibernated instance, stop the instance, and start it.

  • AWS constantly updates its platform with upgrades and security patches, which can conflict with existing hibernated instances. They notify you about critical updates that require a start for hibernated instances so that AWS can perform a shutdown or a reboot to apply the necessary upgrades and security patches.

Enable hibernation for an instance

To hibernate an instance, you must first enable it for hibernation while launching the instance.

🛑
You can't enable or disable hibernation for an instance after you launch it.
To enable hibernation using the console
  1. Follow the procedure to launch an instance, but don't launch the instance until you've completed the following steps to enable hibernation.

  2. To enable hibernation, configure the following fields in the launch instance wizard:

    1. Under Application and OS Images (Amazon Machine Image), select an AMI that supports hibernation. For more information, see Supported Linux AMIs.

    2. Under Instance type, select a supported instance type. For more information, see Supported instance families.

    3. Under Configure storage, choose Advanced (at the right), and specify the following information for the root volume:

      • For Size (GiB), enter the EBS root volume size. The volume must be large enough to store the RAM contents and accommodate your expected usage.

      • For Volume type, select a supported EBS volume type: General Purpose SSD (gp2 and gp3) or Provisioned IOPS SSD (io1 and io2).

      • For Encrypted, choose Yes. If you enabled encryption by default in this AWS Region, Yes is selected.

      • For KMS key, select the encryption key for the volume. If you enabled encryption by default in this AWS Region, the default encryption key is selected.

For more information about the prerequisites for the root volume, see Hibernation prerequisites.

  1. Expand Advanced details, and for Stop - Hibernate behavior, choose Enable.

  1. In the Summary panel, review your instance configuration, and then choose Launch instance. For more information, see Launch an instance using the new launch instance wizard.

To view if an instance is enabled for hibernation

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Instances.

  3. Select the instance and, on the Details tab, in the Instance details section, inspect Stop-hibernate behavior. Enabled indicates that the instance is enabled for hibernation.

Hibernate an instance

You can hibernate an instance if the instance is enabled for hibernation and meets the hibernation prerequisites. If an instance cannot hibernate successfully, a normal shutdown occurs.

To hibernate an Amazon EBS-backed instance
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Instances.

  3. Select an instance, and choose Instance state, Hibernate instance. If Hibernate instance is disabled, the instance is already hibernated or stopped, or it can't be hibernated. For more information, see Hibernation prerequisites.

  4. When prompted for confirmation, choose Hibernate.

    It can take a few minutes for the instance to hibernate. The instance state first changes to Stopping, and then changes to Stopped when the instance has hibernated.

To view if hibernation was initiated on an instance

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Instances.

  3. Select the instance and, on the Details tab, in the Instance details section, inspect State transition message.

    The message Client.UserInitiatedHibernate: User initiated hibernate indicates that hibernation was initiated on the instance.

References

  1. Hibernate your On-Demand Linux instance

  2. Troubleshoot hibernation