Amazon Machine Images ( AMI )

Learn via video courses
Topics Covered

Overview

The core component of any device is its operating system. From a phone to a laptop to even an Amazon EC2 Instance. An Amazon Machine Image (or AMI for short) is the template that contains the operating system as well as other important libraries for an Amazon EC2 Instance to use. Let's take a look at what is AMI in AWS, the key concepts of AMI, and how to create an AMI.

Amazon Machine Image ( AMI )

An Amazon Machine Image or AMI is essentially a template for an Amazon EC2 Instance. When you create a new EC2 Instance, you need to choose an Amazon Machine Image. This Amazon Machine Image will contain which operating system to use along with additional libraries or software.

An EC2 instance is a copy of the AMI running as a virtual server in the cloud. You can launch multiple instances, of different EC2 Instance Types, using the same AMI.

One of the most widely used AMIs is the AMIs provided by AWS - namely the Amazon Linux 2 AMI and Amazon Linux AMI. These AMIs are supported and maintained by AWS. They are based on Linux (Cent OS) and are provided at no additional cost to Amazon EC2 users.

Why Do We Need Amazon Machine Image?

Amazon Machine Images have many uses which make them a core part of Amazon's EC2 Instances. Let's take a look at a few uses:

Base Template for EC2

The fundamental reason for using an AMI is to use it as a template for EC2 instances. AMIs allow you to easily choose an image to use, where these images can range from just the operating system to images with essential libraries installed, and even fully customized images.

Imagine you have just got a brand new laptop or phone. Now you will need to painstakingly install all the applications you use. It would be nice if your favorite applications came pre-installed on the laptop or phone. An AMI essentially solves this problem, but for EC2 instances. Instead of requiring you to install the required applications and libraries each time you launch a new Amazon EC2 Instance, an AMI contains essential applications and libraries, and can be further customized to suit your requirements.

Customized Images

An AMI can be customized to contain applications or libraries which you find necessary. For example, if you are using EC2 instances to host your database, you can install the database on one EC2 instance and create a new AMI with the database installed. Now the next time you want to launch an EC2 instance with the database, you can just use the custom AMI you created earlier. In case you need to upgrade the database version, then you can create a new AMI with the upgraded version, and use this AMI to launch instances. This saves time and makes maintenance easier.

Auto-Scaling

Another use case of AMIs is auto-scaling. If you need to automatically scale the number of EC2 instances you are running in production traffic due to a surge in traffic or higher CPU utilization then you need to specify an AMI to use for the auto-scaling. This AMI can be a custom AMI that contains your application (like a web server) or service (like a database). This allows to you scale automatically without the need to manually create EC2 instances to meet your resource demands.

Key Terminology Associated with Amazon Machine Image

To understand Amazon Machine Images fully, you need to grasp the following key terminologies associated with AMIs:

  1. Amazon EC2 Instance: An Amazon EC2 Instance is the virtual machine or virtual server where an AMI can be run. When you create a new EC2 Instance, you need to select which AMI to use.
  2. Amazon EBS Volume: Amazon EBS Volume is a service from AWS which provides storage volumes that can be used with Amazon EC2 Instances. EBS Volumes are also used while creating AMIs backed by EBS.
  3. Amazon S3: Amazon S3 is a global file storage solution offered by AWS. Amazon S3 is used when you create an AMI backed by Instance Storage.

Lifecycle of Amazon Machine Image

Let's look at the different stages in the Lifecycle of the Amazon Machine Image:

  1. Create an AMI: Create an AMI using an existing EC2 instance. You can create two types of AMI (which will be discussed later) - EBS-backed AMI and store-backed AMI. Each AMI will be associated with an AMI ID.
  2. Copy an AMI: You have the option to copy this AMI to different regions in the same AWS account or share it to an entirely different AWS account.
  3. Launch using an AMI: You can launch instances using the AMI you have created by choosing the specific AMI ID.
  4. Deregister an AMI: Once you no longer need an AMI you can register it, which will then delete the AMI from your account. This AMI will no longer be available when you want to create new EC2 instances. Existing EC2 instances that were created with the deregistered AMI will not be impacted.

Characteristics of Amazon Machine Image

Now that you have understood what an AMI is and its lifecycle, let's dig into the key concepts of an AMI, starting with the Characteristics of an Amazon Machine Image:

1. Regions

An AMI is tied to a region. When you need to use an AMI in a different region or different AWS account, you will need to share that AMI.

2. Operating System

AMIs support all the different operating systems - Linux, Windows, and Mac OS.

3. Architecture

AMIs can be built using 32-bit (x86) or 64-bit (x64) architecture. AMIs also now support ARM.

4. Launch Permissions

An AMI's availability is determined by the Launch Permissions configured by the owner. There are three types of launch permissions - public (available for all AWS accounts), explicit (available for specific AWS accounts), and implicit (available only to the owner of the AMI)

5. Storage for the Root Device

All AMIs are categorized as either backed by Amazon EBS or backed by Instance Store.

  1. Backed by Amazon EBS: An AMI with the root volume created using an Amazon Elastic Block Store (Amazon EBS) volume. This ensures that the data is persisted, even after the EC2 instance is shut down.
  2. Backed by Instance Store: An AMI that uses an Instance Store volume created from a template stored in Amazon S3. When using an Instance Stored-backed AMI, the data in the EC2 instance is not persisted after shut down since the instance gets terminated.

Here's a comprehensive comparison between these two types:

CharacteristicAmazon EBS-backed AMIAmazon instance store-backed AMI
Boot time for an instanceUsually less than 1 minuteUsually less than 5 minutes
Root device volumeEBS volumeInstance store volume
Data persistenceBy default, the root volume is deleted when the instance terminates. But the data on any other EBS volume persists.Data on any instance store volumes is deleted when the instance terminates.
ModificationsWhen the instance is in the stopped state some modifications can be done, for example to the instance type and kernel.No modifications can be done.
ChargesCharged for instance usage, EBS volume usage, and storing the AMI as an EBS snapshot.Charged for instance usage and storing your AMI in Amazon S3.
Stopped stateCan be in a stopped state. Even when the instance is stopped and not running, the root volume is persisted in Amazon EBS.Cannot be in a stopped state, instances are running or terminated.

Types of Amazon Machine Image

There are three types of Amazon Machine Images available. You can choose between any of these types while creating your Amazon EC2 Instance.

Let's take a look at the different types of Amazon Machine Images:

  1. Public: These are the AMIs that are provided by Amazon and the Amazon EC2 community. These are generally available at no additional cost. A popular example is the Amazon Linux 2 AMI, which is maintained by AWS.
  2. Shared: These are the AMIs that a developer or an organization has created and made available for others to use, at no additional cost. Shared AMIs need to be used with caution as these could come from unverified sources. AMIs can also be shared with specific AWS Accounts without making the AMI public.
  3. Paid: These are the AMIs that you can purchase from a developer or an organization. These AMIs are charged according to the rates set by the owner of the AMI. The AWS Marketplace enables you to sell and market your AMI. Paid AMIs usually offer a unique feature or proposition compared to Public or Shared AMIs.

Amazon Linux AMI Virtualization Types

There are two AMI Virtualization Types available. The recommended type from AWS is hardware virtual machine or HVM AMIs.

Let's understand the different Amazon Linux AMI Virtualization Types:

  1. Hardware Virtual Machine or HVM:

    • HVM AMIs support fully virtualized hardware which provides the ability to run an operating system directly on top of a virtual machine without any modification
    • HVM AMIs can take advantage of hardware extensions for enhanced networking and GPU processing
    • This is recommended type of AMI from AWS given the performance benefit compared to PV AMIs
  2. Paravirtual or PV:

    • PV AMIs can run on host hardware that does not have support for virtualization. It achieves this by using a special boot loader called PV-GRUB.
    • PV AMIs cannot take advantage of hardware extensions.
    • PV AMIs are also supported by only a few instance types and only in a few regions.

Buying, Selling, and Deregistering AMIs

When you create Amazon EC2 Instance, you can buy Paid AMIs from the AWS Marketplace and use these to launch your instances. These Paid AMIs are bundled with different benefits like hardened security or specialized software. Using Paid AMIs will incur a cost that is set by the owner of the AMI. You can also sell your custom-made AMIs on the AWS Marketplace.

As discussed in the Lifecycle of Amazon Machine Image section, users have the ability to deregister an AMI they own. When an AMI is deregistered, the AMI is deleted from the AWS Account. But the instances created from that AMI before deregistration will be not impacted in any way. You can choose to deregister an AMI for various reasons, like the image becoming deprecated, using older versions of libraries, or a change in your application's architecture.

How to Create an AMI From an Amazon EC2 Instance?

Now that you understand what an AMI is and what its key properties are, let's explore how to create an AMI and then copy that AMI to a different region.

The screenshots are taken using the New AWS Console. If you are using the Old AWS Console, you can still follow the same steps.

Pre-Requisites

  • AWS Account
  • An Amazon EC2 Instance

Note: If you want to learn how to create an Amazon EC2 Instance, you can out our article on EC2 Instances here.

Steps

  1. log in to your AWS Account.
  2. Open the AWS Console. Search for "EC2" in the Search Bar. Select EC2.
  3. From the EC2 Dashboard, go to Instances. EC2 Dashboard
  4. From the list of Instances, search for the Amazon EC2 Instance you want to use to create an AMI. EC2 Instance
  5. Select the Amazon EC2 Instance. Then click Actions -> Image and templates -> Create image. Creating Image
  6. In the Create image page:
    • Add an Image name. This name cannot be changed later.
    • If you don't want your EC2 Instance to reboot, check the No reboot option. Otherwise, you can leave it unchecked.
    • Make sure Delete on termination is selected under Instance volumes. Only uncheck this option if you want to preserve the EBS volume even after the AMI is deleted.
    • Optionally, add a Name tag under the Tags section.
    • Keep the other settings as default.
    • Click the Create image button. Steps to Create Image
  7. You should see a message like this: Steps to create ami
  8. Click on the "ami-******" link. After a few minutes (or a few hours depending on how large your instance is), the AMI will be ready for use! You can find your AMI anytime in the EC2 Dashboard -> AMIs section.

Copying an AMI to Another AWS Region

The screenshots are taken using the New AWS Console. If you are using the Old AWS Console, you can still follow the same steps.

Pre-Requisites

  • AWS Account
  • An Amazon Machine Image (AMI)

Note: If you want to learn how to create an AMI, you refer to the above section How to Create an AMI from an Amazon EC2 Instance?.

Steps

  1. log in to your AWS Account.
  2. Open the AWS Console. Search for "EC2" in the Search Bar. Select EC2.
  3. From the EC2 Dashboard, go to Images.
  4. From the list of AMIs, search for the AMI you want to copy to another AWS Region.
  5. Select the AMI. Then click Actions -> Copy AMI.
  6. In the Copy AMI page:
    • Optionally, change the AMI copy name or AMI copy description. Otherwise, keep the defaults.
    • Select a Destination Region.
    • Keep the other settings as default.
    • Click the Copy AMI button.
  7. You should see a message like this:
  8. Change the AWS Region to the Destination Region you selected earlier.
  9. After a few minutes (or a few hours depending on how large your AMI is), the AMI will be copied over and ready for use in your Destination Region! You can find your AMI anytime in the EC2 Dashboard -> AMIs section.

Benefits of Using Amazon Machine Image

Amazon Machine Images have a wide variety of uses. Here are some of the key benefits of AMIs:

  • AMIs allow for easy creation of Amazon EC2 Instances - they provide the configuration required for the Operating System, libraries, and other tools to be installed. This enables faster setup times.
  • AMIs are a way to share custom-made images with other users or in your organization with ease.
  • AMIs offer widespread compatibility - in the Operating System (Linux, Windows or Mac OS), in the Architecture (32-bit or 64-bit) or Root Volume Storage (EBS based or Instance Store backed)
  • The AWS Marketplace provides a facility to sell and buy AMIs - enabling users to benefit from the EC2 community.
  • AMIs can act as version control for your application's deployment image. You can create new AMIs each time a new version of your application is available and share that AMI with others.
  • AMIs are required for Auto Scaling Groups (ASGs). When auto-scaling occurs, the specified AMI is used to create the EC2 instance.

Conclusion

  • In this article, you learned about what is Amazon Machine Image (AMI) in AWS and the important concepts related to AMIs.
  • We first understood the lifecycle of an AMI - which involves AMI creation, copying, launching, and deregistration.
  • Then we understood the key characteristics of an AMI - like Region, Operating System, Architecture, Launch Permissions, and Root Volume Storage Types.
  • We then delved into types of AMIs (public, shared, and paid) and the virtualization types supported by AMIs (HVM and PV).
  • We went through the steps of creating an AMI using an Amazon EC2 Instance and then the steps of copying an AMI to another AWS Region.
  • Finally, we concluded by going through the different benefits of using an Amazon Machine Image.