AWS- EC2 Hibernate

EC2 Hibernate is a feature that allows you to preserve the in-memory state (RAM) of an EC2 instance when it is stopped, enabling faster startup times compared to a standard stop/start cycle. This can be particularly useful for applications that require long initialization times or need to maintain an in-memory state.

Nidhi Ashtikar
3 min readJul 10, 2024

Key Points:

  • Stop: Data on EBS volumes is preserved, but the RAM state is lost. The instance shuts down completely.
  • Start: Instance boots up from scratch, OS initializes, EC2 User Data runs, applications start and caches warm up.

Hibernate:

  • Preserve RAM State: The contents of the RAM are saved to the root EBS volume.
  • Faster Boot Time: The instance resumes from where it left off, with the in-memory state restored.

Hibernation Process:

Instance enters stopping state.
RAM contents are saved to the encrypted root EBS volume.
Instance shuts down and RAM is cleared.

Resumption Process:

Instance starts.
RAM contents are loaded from the EBS volume.
Instance resumes exactly where it was before hibernation.

Use Cases:

  • Long-running processes that need to maintain state.
  • Applications with significant initialization times.
  • Fast boot requirements where reinitialization of services is time-consuming.

Requirements and Limitations:

  • Instance RAM: Must be less than 150 GB (this limit can change).
  • Root Volume: This must be an EBS volume, encrypted, and large enough to store the RAM dump.
  • Instance Types: Not supported on bare metal instances.
  • Operating Systems: Supported on various Linux and Windows distributions.
  • Instance Types: Available for on-demand, reserved, and spot instances.
  • Hibernation Duration: Meant for durations no longer than 60 days (this limit can change).

EC2 Hibernate Hands-On Demo

Objective

Demonstrate how to enable and use EC2 hibernation to preserve instance state and achieve faster startup times.

Steps

Launch an Instance

  • Launch an Amazon Linux 2 instance (t2.micro) with a key pair and existing security group (launch-wizard-1).
  • Configure storage ensuring the root EBS volume is encrypted and has sufficient size to store RAM content.

Enable Hibernation

  • During the instance launch, enable hibernation in the “Advanced Details” section.
  • Ensure the root EBS volume is encrypted with the default AWS/EBS key.

Access the Instance

  • Connect to the instance using EC2 Instance Connect or SSH.

Verify Uptime

  • Use the uptime command to check how long the instance has been running since its last start.

Hibernate the Instance

  • Stop the instance using “Instance State” -> “Hibernate instance” option. Wait until the instance is stopped.

Start the Instance

  • Start the instance again from the EC2 console.

Verify Uptime After Hibernation

  • Connect to the instance again and use the uptime command.
  • Notice that the uptime reflects the time since the instance was hibernated, not from a full stop/start cycle.

Terminate the Instance

  • Once verified, terminate the instance to clean up resources.

If you found this guide helpful then do click on 👏 the button.

Follow for more Learning like this 😊

If there’s a specific topic you’re curious about, feel free to drop a personal note or comment. I’m here to help you explore whatever interests you!

Thanks for spending your valuable time learning to enhance your knowledge!

--

--

Nidhi Ashtikar
Nidhi Ashtikar

Written by Nidhi Ashtikar

Experienced AWS DevOps professional with a passion for writing insightful articles.

No responses yet