> ## 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.

# Creating AMI From EC2 Instance

> Hands-on lab · 45m

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/creating-ami-from-ec2-instance" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab details

1. This lab walks you through the steps to create an AMI from an Amazon EC2 instance. You will practice using Amazon Machine Images to launch Amazon EC2 instances and will create an AMI of your EC2 Instance.
2. Duration: **60 minutes**
3. AWS Region: **US East (N. Virginia) us-east-1.**

### Introduction

#### What is AMI?

* AMI stands for Amazon Machine Image.
* It's a master image for the creation of virtual servers, i.e., EC2 instances in the AWS environment.
* They are like templates that are configured with an operating system and other software, which determine the user's operating environment.
* AMIs are categorized according to region, operating system, system architecture (32 or 64 bit), launch permissions and whether they are backed by **Amazon EBS** or by the **Instance Store**.
* AMI includes a template for the root volume required for an instance; a typical example might contain an operating system, an application server and applications.
* When you launch an instance, the root device volume contains the image used to boot the instance.
* In the initial stages, all AMIs were backed by the Amazon EC2 Instance Store. This means the root device for an instance launched from the AMI is an Instance Store volume created from a template stored in Amazon S3.
* Any data on the instance store volumes persists as-long-as the instance is running, i.e., the data gets deleted once the instance is **terminated**.
* Instance store backed instances do not support the **Stop** action.
* If using an instance store is required, Amazon recommends distributing the data across multiple Availability Zones.
* After the introduction of **Amazon EBS**, Amazon introduced AMIs that are backed by Amazon EBS i.e., the root device for an instance launched from the AMI is an Amazon EBS volume created from an EBS Snapshot.
* Amazon recommends using **EBS backed AMIs**, because they launch faster and use persistent storage.
* Amazon EBS backed instances can be stopped and later restarted without affecting data stored in the attached volumes.
* Permissions are controlled to constrain AMIs for instance launches to the appropriate AWS accounts.
* A block device mapping ensures that the correct volumes are attached to the launched instance.
* Users have the facility of selecting AMI provided by AWS, the user community, or through the AWS Marketplace.
* Users can also create their own AMIs and share them within the same region or across regions.

### Architecture diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/001.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=d648a37d92d342afdedc6cf7cd33208d" alt="" width="1000" height="480" data-path="images/labs/creating-ami-from-ec2-instance/001.png" />

### Task details

1. Sign in to AWS Management Console
2. Launching an EC2 Instance.
3. Create a new AMI using the EC2 Instance.
4. Checking the newly created with AMI.
5. Launching the EC2 instance created with the created AMI and testing the AMI.
6. Validation of the lab.

### 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 username**, **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 **Username** 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.**

<Note>
  If you face any issues, please go through [**FAQs and Troubleshooting**](/aws-cp/support/faqs-and-troubleshooting).
</Note>

#### Task 2: Launching an EC2 Instance

1. Make sure you are in the **US East (N. Virginia) us-east-1** Region.
2. Navigate to **Services** menu in the top, then click on the **EC2** in the **Compute** section.
3. Navigate to **Instances** on the left panel and click on **Launch instances** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/002.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=73dbb4d70823e9e88ad0f08c7e71c61a" alt="" width="1615" height="316" data-path="images/labs/creating-ami-from-ec2-instance/002.png" />

4. **Name :** Enter **MyEC2Server**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/003.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=563167195809cd716fd57230baf60551" alt="" width="971" height="194" data-path="images/labs/creating-ami-from-ec2-instance/003.png" />

5. **For Amazon Machine Image (AMI):** Search for **Amazon Linux 2023 kernel AMI** in the Quick Start menu
6. **For Instance Type:** Select **t2.micro**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/004.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=76c3585aa93989358fcfcc457c3804f8" alt="" width="879" height="472" data-path="images/labs/creating-ami-from-ec2-instance/004.png" />

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/005.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=abb30bdf9b3d4cfe6a3783738e8533ac" alt="" width="866" height="220" data-path="images/labs/creating-ami-from-ec2-instance/005.png" />

7. **For Key pair:** Select **Create a new key pair** Button

   * Key pair name: Enter **WhizKey**
   * Key pair type: Select **RSA**
   * Private key file format: Select **.pem**
8. Select **Create key pair** Button.
9. In Network Settings, Click on **Edit**:

* Auto-assign public IP: **Enable**
* Select **Create new Security group**
* Security group name : Enter **MyEC2Server\_SG**
* Description : Enter **Security Group to allow traffic to EC2**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/006.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=2f5e7ce856c7a3fddfb3af9d4bb0544e" alt="" width="975" height="472" data-path="images/labs/creating-ami-from-ec2-instance/006.png" />

* To add **SSH:**

  * Choose Type: **SSH**
  * Source: **Anywhere**
* For **HTTP:**

  * Click on **Add security group rule**
  * Choose Type: **HTTP**
  * Source: **Anywhere**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/007.gif?s=bf1d13994294b5dea9e3f8a6bcab37ee" alt="" width="1000" height="418" data-path="images/labs/creating-ami-from-ec2-instance/007.gif" />

10. Click on **Advanced Details** Under the **User data** section, enter the following script (which creates an HTML page served by an Apache httpd web server).

    ```
    #!/bin/bash
    dnf update -y
    dnf install -y httpd
    echo "<html><h1> Welcome to Whizlabs </h1></html>" > /var/www/html/index.html
    systemctl enable httpd

    systemctl start httpd
    ```

11. Keep rest thing Default and Click on **Launch Instance** Button.

12. Select **View all Instances** to View the Instance you Created

13. **Launch Status:** Your instance is now launching, Navigate to **Instances** page from the left menu and wait until the status of the EC2 Instance changes to running

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/008.jpg?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=d02e20cdf4adc21cdc5a9890dd9b6778" alt="" width="1013" height="108" data-path="images/labs/creating-ami-from-ec2-instance/008.jpg" />

14. Note down the sample IPv4 Public IP Address of the EC2 instance.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/009.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=ebd5d08a8bda68724ca19ac3112d3da1" alt="" width="2448" height="588" data-path="images/labs/creating-ami-from-ec2-instance/009.png" />

15. Enter **[http://your](http://your) IP address**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/010.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=d7bd52180d7db6b0ed01d1a696837bc9" alt="" width="1220" height="752" data-path="images/labs/creating-ami-from-ec2-instance/010.png" />

<Note>
  If the Public IP of the instance is not opening any page, Make sure URL Protocol is **http** not **https**. Please wait until the status check of the instance is transitioned from initializing to **2/2 checks passed**. This may take up to 5 minutes. If still the page does not load, make sure to check the Security group's inbound rule and see if the entry for HTTP exists or not.
</Note>

#### Task 3: Creating an AMI from the EC2 Instance

In this task, we are going to create an AMI from the running EC2 instance created in the previous task. It demonstrates the process of capturing the configuration and contents of an existing instance into a reusable image.

1. Select the **MyEC2Server**. Click on **Actions**.
2. Under **Image and templates**, click on **Create Image**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/011.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=27a987c711aff4c898422b9032251f2e" alt="" width="1615" height="436" data-path="images/labs/creating-ami-from-ec2-instance/011.png" />

3. In the pop-up window, enter the following details:

   * Image Name : Enter **MyEC2Image**
   * Image Description : Enter **My EC2 Image**
   * Leave other details as default.
   * Click on **Create image** button.

#### Task 4: Check the newly created AMI

1. Navigate to **AMI’s** under **Images** on the left menu.
2. You can see that the image is getting generated and status is **pending**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/012.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=4f49fac37812f2fdd385eb5b2d2db99c" alt="" width="1607" height="202" data-path="images/labs/creating-ami-from-ec2-instance/012.png" />

3. Once the process is completed, the status will change to **available**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/013.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=38d55105fb944f5e9f98d18e7a40f958" alt="" width="1616" height="203" data-path="images/labs/creating-ami-from-ec2-instance/013.png" />

4. Now we can use this Image AMI to create brand new instances.

#### Task 5: Launching the EC2 Instance with the Created AMI and Testing the AMI

1. Select the AMI and click on **Launch instance from AMI**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/014.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=638671116d4246823c0c8e3456b3091f" alt="" width="1614" height="197" data-path="images/labs/creating-ami-from-ec2-instance/014.png" />

2. **Name :** Enter **MyEC2AMIServer**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/015.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=1ab43c9bdf9695770598c244d299f208" alt="" width="968" height="182" data-path="images/labs/creating-ami-from-ec2-instance/015.png" />

3. **For Instance Type:** select **t2.micro**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/016.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=3dc6f41dc1caaa707134f94a99d2b319" alt="" width="971" height="260" data-path="images/labs/creating-ami-from-ec2-instance/016.png" />

4. **For Key pair:** Select the key you created previously.
5. In Network Settings :

   * Auto-assign public IP: **Enable**
   * Select **Select existing security group** created earlier.
6. Keep rest thing Default and Click on **Launch Instance** Button.
7. Select **View all Instances** to View the Instance you Created
8. **Launch Status:** Your instances are now launching, Navigate to **Instances** page from left menu and wait the status of the EC2 Instance changes to running
9. Navigate to the instances menu and copy the IPv4 Public IP address of the created EC2 instance.
10. Enter the IP Address in the Browser.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/017.png?fit=max&auto=format&n=vScAll09yOH6D8RK&q=85&s=5e504ab6349cb6f267ad9fc3be5cd5a1" alt="" width="616" height="200" data-path="images/labs/creating-ami-from-ec2-instance/017.png" />

11. You will be able to see the HTML page displaying the message **Welcome to Whizlabs**. This shows that the data in the new instance is the same as the one in the first instance we created.

<Tip>
  **Do you know?**

  The availability of thousands of public AMIs in the AWS Marketplace showcases the flexibility and scalability of the AWS ecosystem. Users can choose from a vast selection of pre-configured AMIs to quickly spin up instances with specific software stacks or use them as a starting point for their own customized environments.
</Tip>

#### Task 6: Validation Test

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/vScAll09yOH6D8RK/images/labs/creating-ami-from-ec2-instance/018.gif?s=210919169c586ccea659a2a6d29fe4d9" alt="" width="996" height="559" data-path="images/labs/creating-ami-from-ec2-instance/018.gif" />

### Completion and conclusion

1. You have successfully created an EC2 instance.
2. You have successfully created an image directly from that EC2 instance.

### End lab

1. Sign out of AWS Account.
2. You have successfully completed the lab.
3. Once you have completed the steps, click on **End lab** in the IP Lab Portal.

## What gets checked

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

* **Launch an EC2 Instance** — Check whether an EC2 Instance is launched or not.
* **Validate EC2 Instance Type t2.micro** — Check whether the EC2 instance type is t2.micro.
* **Launch EC2 AMI type Amazon Linux** — Check whether the EC2 instance is launched using an Amazon AMI.
* **Create an EC2 instance AMI** — Check whether the AMI is created from EC2 or not

## Related help

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