How to Create an Amazon Machine Image (AMI) and use it on AWS

An Amazon Machine Image (AMI) provides the information required to launch an instance. An EC2 instance can not be launched without an AMI. We can create as many instances as we want from a single AMI when we need multiple instances with the same configuration. To create an instance we can use readily available AMI or we can create our own AMI.

To create a custom AMI we need to first launch an instance using one of the available AMIs, make the required configuration on the instance and then use that instance to create an AMI. Instances launched from this new custom AMI include the customizations that we made when we created the AMI. We can create AMIs from either running or stopped instances.

Once we create an AMI, we can either keep it private so that only we can use it, or we can share it with a specified list of AWS accounts. We can also make our custom AMI public so that the community can use it. 

We can also deregister the AMI that is no more needed. After we deregister the AMI, it can't be used to launch new instances. Existing instances created from the deleted AMI can still function and are not affected

In this article, we will see how to create an AMI from an existing EC2 instance and use it to create a new EC2 instance.

Pre-requisites

  1. AWS Account (Create if you don’t have one). 

What we will do?

  1. Login to AWS.
  2. Create an AMI
  3. Use the AMI to create an EC2 instance.

Login to AWS

  1. Click here to go to AWS Login Page.

When we hit the above link, we will see a web page as follows where we are required to login using our login details.

Sign-in to AWS

Once we login into AWS successfully, we will see the main console with all the services listed as follows.

AWS Management console

Create an AMI

Click on "Services" at the top left menu and search for "EC2".

Create an AMI

On the main EC2 dashboard, click on Running instances.

Running instances

Select the instance we want to use as the basis for our AMI then click on Actions -> Image -> Create Image

Actions -> Image -> Create Image

On the "Create Image" screen, type a unique name and description of the AMI to be created, and then choose "Create Image". You can change the Root Volume size as well.

Create image

This will take some time, Click on “View pending image <image_id>” to see the status.

View pending image

When the AMI first appears, it may be in a pending state, but after a few moments, it transitions to an available state.

Launch

Create an EC2 instance from the AMI we created

To create an EC2 instance from the AMI we created, click on Instances from the Left Panel.

Create EC2 from AMI

Click on My AMIs, this page will then display all the AMIs that we have created and are available to use.

List AMI

Once you have selected an AMI, it's time to select the Instance Type. Here, we shall proceed with "t2.micro" as it is eligible for Free Tier Account.

Choose an instance type

On this screen, you can specify the details or you can just click on "Next: Add Storage" to proceed with the default settings. Here, we shall proceed with the default settings.

Configure instance details

You can specify the size for the root partition. We have specified Root Partition Size as 30 GBs. Click on “Next: Add Tags” to proceed.

Add storage

You can specify Tags (Key:Value) or can skip this step and Click on “Next: Configure Security Group”.

Add tags

If you have an existing Security Group you can select that or can create a new one. We shall create a new Security Group by just selecting “Create a new security Group” radio button. Click on "Review and Launch"

Configure security group

Now, review your configuration and click on “Launch”.

Review settings

Before the instance creation starts, we need to select a Key-Pair which is then required to take ssh access to the server. To create a new Key-Pair, select “Create a new Key-Pair” from the drop-down menu, give a name to the Key-Pair, and download it. Keep this Key-Pair at a safe place.

Select key pair

Wait for some time till the instance gets created. Click on “View Instances” to check the Instance State and other details.

Launch status

Once the Instance State changes from “pending” to ‘running’ you can connect to the instance.

Connect to instance

Conclusion

In this article, we saw the steps to create a custom AMI from the existing EC2 instance and created a new EC2 instance using the AMI we created.

Share this page:

0 Comment(s)