DEV Community

Animesh Bhadra 🎯
Animesh Bhadra 🎯

Posted on • Originally published at archerimagine.com on

The complete beginner's guide to AWS AMIs

AWS Made Easy | AWS AMI

Introduction

Have you ever pondered on the question

Why AMI (Amazon Machine Image) is not called Operating System?

If you revisit our previous article, where the first AWS EC2 instance in free tier was created, see Step by Step guide to create an EC2 instance,. The first selection was for AMI.

AWS Made Easy | AWS EC2 | Ubuntu AMI

In this article you will find out, Why Amazon Machine Image (AMI) is not called operating system? This article is everything, you need to understand AWS AMIs.

You will also get answer's to these questions

Why are they referred to as AMI?

What does the AMI cost?

This article will enlighten you with the AWS AMIs inner working. It also explains that you pay for the AMI, when you get bill for your EC2 instance.

This will be a beginner friendly resource. For an experienced person, it will provide some details which you might have ignored.

Let's say Hello World to the Amazon AMIs.

What is AMI?

You should understand by now, AMI stands for Amazon Machine Image.

What is an Amazon Machine Image, the answer depends on the Storage supported.

An AMI includes these things depending on the Storage supported

  • Amazon Elastic Block Storage
    • It provides the snapshot. This snapshot will include the operating system, or any other application required.
  • Instance Store Backed
    • It is a template, providing
    • Operating system
    • Application server
    • Application.

Amazon Elastic Block Storage and Instance Store, they both provide the same details.

You can extract the details of an AWS AMI, by the use of an API describe-images. To use this API, you might need the AMI Id.

In the previous post to create Free Tier AWS EC2 instance, see Step by Step guide to create an EC2 instance, you used the Ubuntu AMI.

It has a unique identifier call AMI ID, as highlighted in the image below.

AWS Made Easy | AWS EC2 | Ubuntu AMI ID

You will use the AWS CLI, to execute this command

aws ec2 describe-images --image-ids ami-0d758c1134823146a

Enter fullscreen mode Exit fullscreen mode

The output is

{
    "Images": [
        {
            "Architecture": "x86_64",
            "CreationDate": "2021-02-24T18:24:50.000Z",
            "ImageId": "ami-0d758c1134823146a",
            "ImageLocation": "099720109477/ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20210223",
            "ImageType": "machine",
            "Public": true,
            "OwnerId": "099720109477",
            "PlatformDetails": "Linux/UNIX",
            "UsageOperation": "RunInstances",
            "State": "available",
            "BlockDeviceMappings": [
                {
                    "DeviceName": "/dev/sda1",
                    "Ebs": {
                        "DeleteOnTermination": true,
                        "SnapshotId": "snap-072d11ffd95664698",
                        "VolumeSize": 8,
                        "VolumeType": "gp2",
                        "Encrypted": false
                    }
                },
                {
                    "DeviceName": "/dev/sdb",
                    "VirtualName": "ephemeral0"
                },
                {
                    "DeviceName": "/dev/sdc",
                    "VirtualName": "ephemeral1"
                }
            ],
            "Description": "Canonical, Ubuntu, 20.04 LTS, amd64 focal image build on 2021-02-23",
            "EnaSupport": true,
            "Hypervisor": "xen",
            "Name": "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20210223",
            "RootDeviceName": "/dev/sda1",
            "RootDeviceType": "ebs",
            "SriovNetSupport": "simple",
            "VirtualizationType": "hvm"
        }
    ]
}

Enter fullscreen mode Exit fullscreen mode

This tells me all about the AMI, which family the AMI belongs, What is the Virtualization type. It also tells what is the root device type.

The above information is also present in the below screen.

AWS Made Easy | AWS EC2 | Ubuntu AMI ID details

As mentioned above, each AMIs has 3 information in itself, you will try to find these 3 information first.

  • Is the above AMI an EBS backed or Instance Store.
    • "RootDeviceType": "ebs",
  • What is the operating system?
    • "PlatformDetails": "Linux/UNIX",
    • "Description": "Canonical, Ubuntu, 20.04 LTS, amd64 focal image build on 2021-02-23",
  • It will be created from this snapshot id "SnapshotId": "snap-072d11ffd95664698",
  • There is no additional application server or any other application installed.

The above AMI is a bare bone Ubuntu Image.

If you want, you can install your own Web Server Apache2, or any other application and then create an AMI from it.

The next natural progression should be to explore what is the use of AWS AMIs?

What is the use of AMIs?

If you observe the image below, you can understand 2 basic uses of the AMIs, Can you please guess the 2 use you can think of?

AWS Made Easy | AWS EC2 | Use of AWS AMIs

Before I can give you the answer to the above question, you should comprehend the above Image.

The first step is to create an EBS Snapshot, Once you have the EBS Snapshot, you should register the AMI.

These two steps are not required if you are choosing an existing AMI.

In Addition, the above image shows us the 3 use or life cycle of the AMI

  • Launch
    • launches an AWS EC2 instance from AMI
  • Copy
    • You can copy an existing AMI, for future use.
  • De-register
    • You can de-register the AMI if not used.

If you have guessed any two use from the above image, please pat your back.

Once you are clear with the life cycle / use of an AWS AMIs, you should proceed towards seeing the types of AMIs.

Region, Operating System, Architecture, and Storage can define the AMI's classification. Let's us discuss them.

Types of AMI

Region (see Regions and Zones)

The region restricts the availability of a particular AMI.

If you check Ohio (us-east-2), the number of public AMIs are 69,431.

AWS Made Easy | AWS EC2 | AWS AMI in us-east-2

If you check for N.Virginia (us-east-1), the number of public AMIs are 140,650.

AWS Made Easy | AWS EC2 | AWS AMI in us-east-1

The above numbers can change in the future. The disparity between region for AMIs will still be present.

The AMI are region specific. You can create EC2 instance with the AMI present in that region.

If you want any other AMI from a different region you may have to copy those AMIs to your region.

Operating System & Architecture

You have already seen, AMIs are available for both Linux and Windows. There are different variants for both the operating system.

You also have both 32-bit and 64-bit architecture support in these.

Launch permissions

The AMI owner can specify the availability, by providing the launch permission. There are three types of launch permissions

  • public - Anyone on AWS can launch using this AMI
  • explicit - One account can grant explicit permission to another account.
  • implicit - Owner of the AMI has implicit permission to launch.

You will learn about public, explicit and implicit AMIs once you reach a state of creating AMIs. Till that time being, you can read this article on the same, see Share an AMI with specific AWS accounts.

Storage for the root device

The storage of the root device, creates two distinct classifications of AMI Types.

  • Backed by AWS EBS
    • The root device would be an AWS Elastic Block Store
  • Backed by AWS Instance Store.
    • The root device would be an instance store volume, created from a template.
Property AWS EBS AWS Instance Store
Boot time less than 1 minute less than 5 min
Size Limit 16 TiB 10 GB
Root device volume EBS Instance Store
Data Persistence Root Volume data is deleted, Non root EBS is persisted Data is persists only till life of the instance
Modification Instance type, Kernel, Ram Disk, User data can be changed in stopped state It is fixed.
Charges Charged for instance use, EBS volume usage and Storing of AMI as EBS Snapshot Instance usage and AMI storage on S3
AMI Creation Single command requires installation and use of AMI tool
Stopped State Can be in stopped state Cannot be in stopped state.

AWS Made Easy | AWS EC2 | AWS EBS Vs Instance Store

You might have this question in mind, Why should you use Instance Store, when EBS is better in all aspects?

Instance Store is the option when you need low latency. Read and write are faster because host has the volume mounted. Check out the result published here.

Instance store is ephemeral. This makes them a perfect candidate for temporary data which changes very often.

Linux AMI virtualization types

You might be thinking, What is Virtualization after all?

Virtualization is a type of abstraction. It allows many machines created from a single computer. It translates the virtual machine into the underlying hardware.

You might have used a Virtual Box to run Linux on your Windows PC, that is also a type of Virtualization.

Virtualization is at the heart for all AWS or any Cloud Provider. You will be running many different operating system on the same piece of hardware.

You might be thinking, How can you run different operating system on the same piece of hardware?

The answer is a technology called HyperVisor or Virtual Machine Monitor (VMM). It allows to host different virtual machine.

The different virtualization techniques used are

  • Full Software Virtualization
  • Hardware-assisted software virtualization or Hardware Virtual Machine (HVM)
  • Paravirtualization or paravitualized Machine (PV)
  • Hardware assisted software virtualization with Paravirtual drivers (PVHVM)
  • Component or resource virtualization

AWS Made Easy | AWS EC2 | Linux Virtualization Types

AWS supports two types of AMIs based on the virtualization techniques.

  • Paravirtual (PV)
  • Hardware virtual machine (HVM)

What are these Paravirtualization or Hardware Virtual Machine (HVM)? Come further the rabbit hole.

Hardware virtual machine (HVM)

CPU Chips with built in virtualization can support Hardware virtual machine (HVM).

The Hardware virtual machine is a type of full software virtualization. It is dependent on the hardware capability. Hardware Virtual Machine (HVM) is the future.

Paravirtualization

In this virtualization techniques, the guest OS uses the facilities provided by the host OS.

PV and HVM AMIs

Have you seen any Paravirtual (PV) or Hardware Virtual Machine (HVM) AMIs in AWS. Check the images below

HVM:-

AWS Made Easy | AWS EC2 | Virtualization HVM

Paravirtual

AWS Made Easy | AWS EC2 | Virtualization PV

You can see that Paravirtual is a thing of the past. It is only available in community AMIs and not present in the Quick Start AMIs.

You have only HVM's as an option in Quick Start AMIs.

HVM Vs PV

Property HVM PV
Description HVM AMIs are presented with a fully Virtualized set of hardware and boot by executing the master boot record of the root block device of the image. PV AMIs boot with a special boot loader called PV-GRUB, which starts the boot cycle and then chain loads the kernel specified in the menu.
Hardware extension Yes, can take advantage No, cannot take any advantage
Instance Type All current generation Only certain generation, like C1, C3, HS1, M1, M3, M2 and T1
Region All Region Asia Pacific (Tokyo), Asia Pacific (Singapore), Asia Pacific (Sydney), Europe (Frankfurt), Europe (Ireland), South America (São Paulo), US East (N. Virginia), US West (N. California), and US West (Oregon)
How to find Virtualization type of the AMI is set to hvm virtualization type of the AMI is set to paravirtual,

AWS Made Easy | AWS EC2 | Difference between HVM and PV

You have understood the difference between the virtualization techniques. Its time to move to understand why would you pay for an AMI?

Shared and Paid AMIs

You can separate the AMIs based on the payment option.

As a Developers, you can share AMIs to the community, which you have created. Other developer's can pick these AMIs for modification. The Community AMIs are falling in this category.

Use of these shared AMIs in production environment without audit is a security risk.

The Paid AMIs are available from AWS Marketplace. It provides high quality licensed software configured in the AMIs. These are generally charged based on the hourly rate given by the owner.

You might be thinking, normal EC2 billing I can understand.

How does a component of that EC2 charges money?

Come with me to find..

Billing

You have executed the describe-images command in What is AMI? section. In the JSON output you got this two details.

{
    "PlatformDetails": "Linux/UNIX",
    "UsageOperation": "RunInstances",
}

Enter fullscreen mode Exit fullscreen mode

These two parameters define the billing of the AMI, and also compatibility.

When launching a spot instance, always check if the spot instance supports the particular PlatformDetails.

In case of Reserved Instance, you should check if the operating system platform lits the AMI PlatformDetails.

The UsageOperation tells the lineitem/Operation in the actual billing of the AWS EC2 instance.

Conclusion

Cloud Computing is possible today because of advancement in virtualization techniques. Hardware virtual machine (HVM) has a special role in this.

AMI (Amazon machine image) has further enhanced the options.. Many instances can use these AMIs to launch identical copies. AMIs are the blueprint. AMIs have a definite life cycle of creating, register, copy, launch and de-register. If you are not creating your own AMI, then you have only last three life cycle states.

AMIs are different based on the region, you are launching. It is different based on the architecture and operating system. It differs in the way different people have access to launch. It is differentiated based on the root device type.

AWS supports only HVM and PV virtualization techniques. Between these, AWS is recommending the HVM and in future you may not even have a PV AMI.

The billing of an EC2 instance includes AMI cost. PlatformDetails & UsageOperation field of the AMI contributes toward this cost.

Hope you are clear with the concept of AMI. If you want to launch an EC2 instance. Checkout, the free tier EC2 instance launch article. see Step by Step guide to create an EC2 instance.

Reference

Top comments (0)