Get started with Amazon Machine Images (AMI)

ยท

7 min read

An Amazon Machine Image (AMI) is a pre-configured virtual machine image used to create virtual servers (instances) in the Amazon Elastic Compute Cloud (EC2). An AMI includes:

  • A root volume template for the instance (which could be an operating system, an application server, and applications).

  • Launch permissions that control which AWS accounts can use the AMI to launch instances.

  • A block device mapping that specifies the volumes to attach to the instance when it's launched.

AMIs provide the information required to launch an instance in EC2. In essence, they serve as a template for new instances. When you want to launch an EC2 instance, you select an AMI, specify the instance type (which determines resources like CPU, memory, storage), configure settings, and then start the instance.

You're not directly billed for creating or using AMIs. However, you are charged for the underlying Amazon S3 storage used by the AMI's snapshot. When an EC2 instance is launched from an AMI, usual EC2 instance charges apply.

๐Ÿ’ก
Ensure that your custom AMIs do not contain sensitive data. If you're sharing them or making them public, ensure they don't have confidential information, access keys, or proprietary software without appropriate licensing.

Benefits of using AMI

Consistency: By using AMIs, you ensure that every instance launched from that AMI has the same configuration.

Speed: Since AMIs include all the necessary configurations, launching an instance from an AMI is much quicker than setting up an instance from scratch.

Portability: AMIs can be copied across AWS regions, allowing you to deploy applications globally.

Recovery: If an instance fails, you can quickly launch a new one using the same AMI.

Use an AMI

The following diagram summarizes the AMI lifecycle. After you create and register an AMI, you can use it to launch new instances. (You can also launch instances from an AMI if the AMI owner grants you launch permissions.) You can copy an AMI within the same AWS Region or to different AWS Regions. When you no longer require an AMI, you can deregister it.

You can search for an AMI that meets the criteria for your instance. You can search for AMIs provided by AWS or AMIs provided by the community. For more information, see AMI types and Find a Linux AMI.

After you launch an instance from an AMI, you can connect to it. When you are connected to an instance, you can use it just like you use any other server.

Create your own AMI

You can launch an instance from an existing AMI, customize the instance (for example, install software on the instance), and then save this updated configuration as a custom AMI. Instances launched from this new custom AMI include the customizations that you made when you created the AMI.

The root storage device of the instance determines the process you follow to create an AMI. The root volume of an instance is either an Amazon Elastic Block Store (Amazon EBS) volume or an instance store volume. For more information about the root device volume, see Amazon EC2 instance root device volume.

In general, there are two types of AMIs:

Buy, share, and sell AMIs

After you create an AMI, you can keep it private so that only you can use it, or you can share it with a specified list of AWS accounts. You can also make your custom AMI public so that the community can use it. Building a safe, secure, usable AMI for public consumption is a fairly straightforward process, if you follow a few simple guidelines. For information about how to create and use shared AMIs, see Shared AMIs.

You can purchase AMIs from a third party, including AMIs that come with service contracts from organizations such as Red Hat. You can also create an AMI and sell it to other Amazon EC2 users. For more information about buying or selling AMIs, see Paid AMIs.

Deregister your AMI

You can deregister an AMI when you have finished with it. After you deregister an AMI, it can't be used to launch new instances. Existing instances launched from the AMI are not affected. For more information, see Deregister your AMI.

Storage for the root device

All AMIs are categorized as either backed by Amazon EBS or backed by instance store.

  • Amazon EBS-backed AMI โ€“ The root device for an instance launched from the AMI is an Amazon Elastic Block Store (Amazon EBS) volume created from an Amazon EBS snapshot.

  • Amazon instance store-backed AMI โ€“ The root device for an instance launched from the AMI is an instance store volume created from a template stored in Amazon S3.

For more information, see Amazon EC2 instance root device volume.

Determine the root device type of your AMI

To determine the root device type of an AMI using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose AMIs, and select the AMI.

  3. On the Details tab, check the value of Root device type as follows:

    • ebs โ€“ This is an EBS-backed AMI.

    • instance store โ€“ This is an an instance store-backed AMI.

To determine the root device type of an AMI using the CLI

  1. Retrieve AMIs owned by your account:

     aws ec2 describe-images --owners self --query 'Images[].ImageId' --output text
    
  2. Determine the root device type of an AMI:

     aws ec2 describe-images --image-ids ami-12345678 --query 'Images[0].RootDeviceType' --output text
    

Create Amazon EBS-backed AMI using the console

Creating an Amazon EBS-backed AMI through the AWS Management Console involves creating an image of an existing EC2 instance. The created AMI will include the root volume (and any additional EBS volumes attached to the instance). Here's a step-by-step guide on how to do this:

  1. Log in to the AWS Management Console:

    Navigate to the EC2 dashboard.

  2. Select the Instance:

    • In the left-hand navigation pane, click on Instances to view all your running EC2 instances.

    • Select (check the box of) the EC2 instance for which you want to create an EBS-backed AMI.

  3. Initiate Create Image:

    • With the instance selected, click on the Actions button.

    • Hover over Image and templates.

    • Click on Create Image from the dropdown menu.

  1. Configure Image Details:

    • Image Name: Provide a unique name for your AMI. This will help you identify the AMI later.

    • Image Description (optional): Add a description to provide more context or notes about the AMI.

    • No Reboot (checkbox): By default, AWS attempts to cleanly shut down the instance, create the image, and then reboot the instance. If you don't want your instance to be shut down, check the No Reboot box. However, be aware that not allowing the instance to reboot might result in a less consistent image.

  2. Create Image:

    • After filling in the necessary details, click the Create Image button.
  3. Monitor Image Creation:

    • After initiating the image creation, you'll be taken to the AMIs section in the EC2 dashboard.

    • Here, you can monitor the progress of your AMI creation. The status will change from pending to available once the image is successfully created.

    • Remember, creating an AMI will also create snapshots of the EBS volumes attached to the instance. You can view these snapshots in the Snapshots section of the EC2 dashboard.

  4. Use the AMI:

    Once the AMI is available, you can use it to launch new EC2 instances with the same configuration as the original instance. When you launch an instance from the AMI, the root volume and any additional volumes will be created from the corresponding snapshots.

You've now successfully created an EBS-backed AMI from an existing EC2 instance using the AWS Management Console.

Launch an instance from an AMI you created

You can launch an instance from an AMI that you created from an instance or snapshot.

To launch an instance from your AMI
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, under Images, choose AMIs.

  3. Set the filter to Owned by me and select your AMI.

  4. Choose Launch instance from AMI (new console) or Actions, Launch (old console).

  5. Accept the default values or specify custom values in the launch instance wizard. For more information, see Launch an instance using the new launch instance wizard

References

  1. Amazon Machine Images (AMI)
ย