> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Hibernating an EC2 Instance

> Hands-on lab · 30m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/hibernating-an-ec2-instance" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab details

1. This lab walks you through hibernating an EC2 Instance.
2. Duration: **30 minutes**
3. AWS Region: **US East (N. Virginia) us-east-1**

### Introduction

**What happens when an EC2 instance is hibernated ?**

* When an instance is hibernated, EC2 tells the operating system to suspend-to-disk.
* Hibernation saves the RAM contents to the EBS root volume EC2 persists the instance EBS root volume and any attached EBS data volumes
* When you start your instance after hibernation:

1. EBS root volume is restored to its previous state

2. RAM contents are reloaded.

3. Processes that were previously running on the instance are resumed.

4. Originally attached data volumes are reattached and the instance keeps its instance ID.

### Architecture diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/001.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=d54140e46bb1efb3ccaccd48a6324317" alt="" width="1481" height="1040" data-path="images/labs/hibernating-an-ec2-instance/001.png" />

### Task details

1. Sign into AWS Management Console.
2. Launch an Instance including Stop-Hibernate option.
3. Testing Hibernation of an EC2 Instance.
4. Validation of the Lab.
5. Deleting AWS Resources.

### Launching the lab environment

1. To launch the lab environment, Click on the **Launch lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM user name**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

<Note>
  You can only start one lab at any given time.
</Note>

## Lab guide

### Lab steps

#### Task 1: Sign in to AWS Management Console

1. Click on the **Open console** button, and you will get redirected to AWS Console in a new browser tab.
2. On the AWS sign-in page,

* Leave the Account ID as default. Never edit/remove the 12 digit Account ID present in the AWS Console. otherwise, you cannot proceed with the lab.
* Now copy your **User Name** and **Password** in the Lab Console to the **IAM Username and Password** in AWS Console and click on the **Sign in** button

3. Once Signed In to the AWS Management Console, Make the default AWS Region as **US East (N. Virginia) us-east-1.**

#### Task 2: Launching an EC2 Instance

1. Navigate to **EC2** by clicking on the **Services** menu in the top, then click on **EC2** in the **Compute** section.

2. Make sure you are in the **US East (N. Virginia) us-east-1** Region.

3. Navigate to **Instances** on the left panel and click on **Launch instances**.

4. Enter the Name for the Instance

* **Name :** Enter **WhizInstance**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/002.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=270a0f4e23a47496647e0ad85cfba54c" alt="" width="973" height="199" data-path="images/labs/hibernating-an-ec2-instance/002.png" />

5. Choose an Amazon Machine Image (AMI): Select **Amazon Linux 2023 AMI** in the drop-down.

* Choose **architecture** as **64-bit(x86)**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/003.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=ac6015fd7482f99542a1207387057d1e" alt="" width="930" height="466" data-path="images/labs/hibernating-an-ec2-instance/003.png" />

6. Choose an **Instance Type**: Select **t2.micro.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/004.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=019f724eddcaf6cd06e5c11b08b5c75d" alt="" width="1008" height="280" data-path="images/labs/hibernating-an-ec2-instance/004.png" />

7. Key Pair: Select **Create a new key pair**

* **Key pair type** : Select ***RSA***
* **Key pair name:**  Enter ***MyEC2Key***
* **Private key file format:** Select ***.pem***
* Click on the **create Key pair** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/005.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=10e699a781b0d4500a5e908792b68449" alt="" width="746" height="789" data-path="images/labs/hibernating-an-ec2-instance/005.png" />

8. Click on the drop-down of the **Network Settings.**

9. Configure Security Group:

* Select **Create security group**
* Select **SSH** type
* Source Type: Select **My IP**.

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/006.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=1a51ca0b4a688bb2ec84fe4da3509775" alt="" width="930" height="600" data-path="images/labs/hibernating-an-ec2-instance/006.png" />

10. Click on the **Advanced** option at the top right corner of the **Configure Storage.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/007.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=28e953420f53ca66bd0b075ca96f3161" alt="" width="926" height="171" data-path="images/labs/hibernating-an-ec2-instance/007.png" />

11. Click on **Volume 1 (AMI Root).**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/008.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=d9420090a50d6a968622371bf0ca5e06" alt="" width="972" height="361" data-path="images/labs/hibernating-an-ec2-instance/008.png" />

12. Select **Encrypted** option from the **Encrypted** drop-down and (**default) aws/ebs key** from the **KMS Key** drop-down.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/009.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=3880e6305101c4e35abbb69f9728b3d9" alt="" width="924" height="415" data-path="images/labs/hibernating-an-ec2-instance/009.png" />

13. Click on the **Advanced details** button and select **Enable** from the **Stop-Hibernate Behaviour** drop-down.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/010.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=dfe2b3dcf997afd5efe76dfc27b73b1e" alt="" width="739" height="87" data-path="images/labs/hibernating-an-ec2-instance/010.png" />

14. **Review and Launch**: Review all settings and click on **Launch Instance** at the bottom right.

15. **Launch Status:** Your instance is now launching, Click on the instance ID and wait for complete initialization of the instance till the status changes to **Running**.

#### Task 3: Testing Hibernation of an EC2 Instance

We can test the hibernation of the EC2 either using the Dashboard or using CloudShell.
**Wait till the Status Check of instance become passed.**

##### Method 1:

1. Select the instance from the Instances panel and click on **Instance State.**
2. Click on **Hibernate** Instance.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/011.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=e0983f2c37590d694e085a8242a9f265" alt="" width="1215" height="206" data-path="images/labs/hibernating-an-ec2-instance/011.png" />

3. Select the **Hibernate** button.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/012.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=04c14068d6b7afa2ec9f68dbbf33f558" alt="" width="839" height="269" data-path="images/labs/hibernating-an-ec2-instance/012.png" />
4. You can see that the Instance state has been changed from **Running** to **Stopped.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/013.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=15a5c40da84bd3c7330da4d13f26959a" alt="" width="1579" height="188" data-path="images/labs/hibernating-an-ec2-instance/013.png" />

5. Select the Instance again and Select Instance State as **Start Instance.**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/014.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=f75512a17189a5396be87e85c155e852" alt="" width="1599" height="254" data-path="images/labs/hibernating-an-ec2-instance/014.png" />

6. We can see that Instance starts running again.

##### Method 2:

1. Go to **EC2 Dashboard** and copy the **Instance ID** of your instance.

2. Go to AWS CloudShell by clicking on

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/015.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=373e6ff8d6b78faa9ba316d0a98416f1" alt="" width="37" height="47" data-path="images/labs/hibernating-an-ec2-instance/015.png" />

at the top right of the AWS console.

3. We can use the Stop action to hibernate an instance because we have enabled the **Stop-Hibernation** behavior. To hibernate the instance, run the command:

```
aws ec2 stop-instances --instance-ids <instance_id>
```

<Note>
  Replace \<instance\_id> with the Instance ID you have copied in Step 1. Wait for 2 to 3 minutes for the instance to get stopped.
</Note>

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/016.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=6649d492812c596e5df99ba9906b2d25" alt="" width="464" height="321" data-path="images/labs/hibernating-an-ec2-instance/016.png" />

4. Run the following command to start the instance.

```
aws ec2 start-instances --instance-ids <instance_id>
```

<Note>
  Replace `&lt;instance_id&gt;` with the Instance ID you copied in step 1.
</Note>

5. Wait for a few minutes and run the command again. You can see that the instance state has changed from **pending** to **running** state.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/017.png?fit=max&auto=format&n=O4tXcjEIp2L-crIL&q=85&s=24e3e540bf3bed8c497042fb9d0a360f" alt="" width="476" height="283" data-path="images/labs/hibernating-an-ec2-instance/017.png" />

<Tip>
  **Do you know?**

  Hibernating an Amazon Elastic Compute Cloud (EC2) instance is a feature provided by AWS that allows you to pause an EC2 instance instead of stopping it. When you stop a traditional EC2 instance, it goes into a stopped state, and you're no longer charged for the instance's compute resources (CPU and memory). However, when you start it again, you need to wait for the instance to boot up, which can take some time, and you may lose any in-memory data or configurations that were stored on the instance.
</Tip>

#### Task 4: Validation of the Lab

1. Once the lab steps are completed, please click on the **Check my work** button on the right side panel.

2. This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.

3. Sample output :

<img src="https://mintcdn.com/ip-cloud-architect-pathway/O4tXcjEIp2L-crIL/images/labs/hibernating-an-ec2-instance/018.gif?s=dfb5c13aed0905add39020319a3e389f" alt="" width="1000" height="605" data-path="images/labs/hibernating-an-ec2-instance/018.gif" />

#### Task 5: Deletion of AWS Resources

**1. Terminate EC2 Instance :-**

* In the navigation pane, choose **Instances**.
* Select the instance, and choose **Instance state** and click on **Terminate instance**.
* Choose **Terminate** when prompted for confirmation.

### Completion and conclusion

1. You have successfully launched an EC2 Instance.
2. You have successfully hibernated an EC2 Instance.

### End lab

1. Sign out of the AWS Account.
2. You have successfully completed the lab.
3. Click on **End lab** button in the IP Lab Portal and wait till the process gets completed.

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Login to AWS Management Console** — Check whether the user has logged in to the AWS Management Console.
* **Hibernate an EC2 Instance** — Check if an amazon linux EC2 instance launched with Stop-Hibernate Behaviour enabled or not.

## Related help

* [FAQs and Troubleshooting](/aws-cp/support/faqs-and-troubleshooting)
