Tuesday, April 29, 2025

EC2 Hibernate (Pause instance & Resume Later) | Overview & Hands-On.

An Overview & Hands-On for EC2 Hibernate (Pause instance & Resume Later). 

Focus:

  • Tailored for SRE, DevOps, Cloud, and DevSecOps Engineers

Breakdown:

  • Intro,
  • How EC2 Hibernate Works,
  • Prerequisites and Limitations,
  • Hibernation for an EC2 instance & specific conditions,
  • How to Enable & Use EC2 Hibernate,
  • Quick idea to remeber,
  • Key things about EC2 Hibernate,
  • Common use cases,
  • Insights,
  • Architecture diagram,
  • Hands-On

Intro:

  • EC2 hibernate is an Amazon Web Services feature that allows twtech to stop and then resume an EC2 instance, preserving its in-memory state (RAM) to an encrypted Amazon Elastic Block Store (EBS) root volume.
  • This enables faster restarts and allows applications to pick up exactly where they left off.
  • EC2 Hibernate is a feature in AWS EC2 that actually pauses an instances and resume it later.
  • Think of EC2 Hibernate as putting a laptop to sleep instead of shutting it down.
How EC2 Hibernate Works
  • When an instance is hibernated, the operating system is signaled to perform a suspend-to-disk action
  • The contents of the instance's RAM are saved to a pre-configured, encrypted EBS root volume
  • The instance then shuts down and enters a stopped state
  • When the instance is restarted, the saved RAM content is loaded back into memory, allowing the instance to resume from its prior state.
  • While an instance is hibernated (in a stopped state), twtech pay only for the attached EBS volumes and Elastic IP addresses; there are no charges for instance usage time.
Prerequisites and Limitations
To use hibernation for an EC2 instance, specific conditions must be met: 
Enablement at Launch
  • Hibernation must be explicitly enabled when launching the instance; it cannot be enabled later.
Encrypted Root Volume:
  •  The root EBS volume must be encrypted to ensure the protection of sensitive data copied from memory.
Supported Instance Types and AMIs:
  •  The feature is available for specific instance types (e.g., M5, R5, T2) and operating systems (e.g., Amazon Linux 2, Ubuntu, Windows Server).
Memory Limit:
  •  An instance cannot be hibernated if it has more than 150 GB of RAM.
Stateless Workloads:
  •  For stateless applications like web servers or microservices, it is often better to use standard stop/start or Auto Scaling features. 
  • Hibernation is best suited for stateful workloads, such as databases or ML jobs, that benefit from state preservation.
How to Enable and Use EC2 Hibernate
Launch Instance:
  •  In the "Launch an instance" wizard within the Amazon EC2 console, navigate to the Advanced Details section.
Enable Hibernation:
  •  Under the Stop - Hibernate behavior setting, select Enable.
Ensure Encryption:
  •  Confirm that the root EBS volume is encrypted during the storage configuration step.
Hibernate:
  •  Once the instance is running, twtech can select it in the dashboard, choose Instance state, and then select Hibernate instance

Quick idea to remember:

  • When twtech hibernates an EC2 instance, AWS saves the contents of the RAM (memory) to twtech instance’s root EBS volume.
  • When twtech start the instance again, it loads the RAM contents back — so all twtech processes, in-memory data, and open sessions are exactly as they were.
  • It's faster than a full reboot and twtech doesn't lose any in-progress data.

Key things about EC2 Hibernate:

  • It only works on instances with EBS root volumes (not instance store).
  • RAM limit: up to 150 GB.
  • twtech need to enable hibernation at instance launch…so it can just turn it on later.
NB:
  • twtech is charged for the EBS storage and any other attached resources while the instance is hibernated, but it is not charged for compute time (since the instance isn’t running).

Common use cases:

  • Use Spot instances where twtech wants fast recovery.
  • For Long-running applications that twtech wants to pause and resume.
  • For Development environments that twtech doesn't want to restart from scratch every time.

twtech-Insights:

  •   EC2 Hibernate Supports Instance Families like: C3, C4, C5, I3, M3, M4, R3, R4, T2, T3...
  •   The Instance RAM Size should be less than 150 GB.
  •   The Instance Size is not supported for bare metal instances.
  •   EC2 Hibernate works for these AMI:  Amazon Linux 2, Linux AMI, Ubuntu, RHEL, CentOS & Window.
  •   The Root Volume should be EBS, encrypted, not instance store, and large.
  • EC2 Hibernate is available for On-Demand, Reserved and Spot Instances.
  NB:
  •  Instances can NOT be hibernated more than 60 days. 
Architecture diagram


Project:Hands-On

How twtech launches an instance with Hibernating feature enabled,

Step-1:

  • Go to EC2 instance console and launch instance.



  •  Selected OS for this project: Redhat

  • twtech must Select the keypair or create one,  if it would subsequently SSH into the instance

  • Configure the advance feature of the EBS volume:

  • Configure to encrypt the EBS volume with aws key

  • Go to instance advance details and navigate to: Stop-Hibernate behavior / select enable


Step-2:

  • Connect (ssh) to instance  and run the uptime command to see how long the instance has been runnig: uptime
NB:

The follow uptime command in Linux (and Unix-like systems) shows how long the system has been running, along with other basic information like the number of users and the system load averages.

#  bash

uptime

output:

01:08:03 up 8 min,  1 user,  load average: 0.00, 0.03, 0.01

  • twteck explanation of what each part of output means:
    • 01:08:03 Current system time.
    • up 8 min  The system has been running for 8 minutes.
    • 1 user  There is 1 user currently logged in to the system.
    • load average:0.00, 0.03, 0.01  The system load averages for the last 0, 3, and 1 minutes.

 Step-3:

  • twtech hibernates the instance eventually.
  • Select the instance, then go to instance state / Hibernate instance

  • Confirm hibernation:


NB:

  • The stopped instance has data stored on the ebs volume.


  • twtech may restart the instance at any time and its data will synchronize from the ebs volume to the Ram.


 Step-4:

  • Wait until instance status is fully initialized : it may take a couple of minutes for data to synchronize from EBS to the RAM.

From

To:

  • twtech successufly created and hibernated its webs server 


No comments:

Post a Comment

Amazon EventBridge | Overview.

Amazon EventBridge - Overview. Scope: Intro, Core Concepts, Key Benefits, Link to official documentation, Insights. Intro: Amazon EventBridg...