AWS Amazon Machine Image (AMI)

Photo by Onkarphoto on Unsplash

AWS Amazon Machine Image (AMI)

What is AWS AMI?

AWS AMI stands for Amazon Machine Image. It is a pre-configured virtual machine image used to create virtual servers (instances) in the Amazon Elastic Compute Cloud (EC2). It includes the necessary information to launch an EC2 instance.

AMI Lifecycle:

  1. Create an AMI;

  2. Register the AMI;

  3. Use the AMI to launch new instances (if the AMI owner grants you launch permissions).

  4. Copy an AMI within the same AWS Region or to different AWS Regions;

  5. When you no longer require an AMI, you can deregister it. After you deregister an AMI, it can't be used to launch new instances. Existing instances launched from the AMI are not affected.

AMI Characteristics

  1. Contents of an AMI: An AMI typically contains:

    • A template for the root volume for the instance (e.g., 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.

  2. Public and Private AMIs: AMIs can be either:

    • Public: Owned by AWS or AWS Marketplace vendors and are available to all AWS customers.

    • Private: Owned by individual AWS accounts and are only available to that account (though they can be shared with specific accounts if desired).

  3. Benefits:

    • Consistency: AMIs provide a predictable environment to deploy applications.

    • Speed: Since AMIs are pre-configured, new instances can be launched quickly.

    • Templating: If you have a specific setup or software stack that you want to replicate across multiple instances, you can create your own custom AMI.

  4. Custom AMIs: Users can create their own AMIs, which is particularly useful if they need a consistent, reproducible environment. Once an EC2 instance is set up to the user's liking, it can be saved as a custom AMI, which can then be used to launch new instances with the same configuration.

  5. Billing: Remember, while you aren't directly charged for the creation or storage of an AMI, you are billed for the Amazon S3 storage that the AMI takes up, and of course, for any EC2 instances you launch using that AMI.

Hands-on Lab Overview

In this hands-on lab, first, we will launch an EC2 instance (CreateCustomAMI) from an existing AMI Amazon Linux 2 AMI. Then, we will customize the instance by installing and starting an Apache web server, and then save this updated configuration as a custom AMI (MyCustomAMI). Next, we will create a second EC2 machine (UseCustomAMI), launch it with our previously created custom AMI MyCustomAMI and create a index.html file. It should appear on the browser.

Hands-on Lab

  1. Launch the EC2 CreateCustomAMI machine from an existing Amazon Linux 2 AMI, add a script that installs and starts Apache Web Server.

  2. Then, access the instance via its public IP address to see whether the Apache server was installed and started correctly:

  3. Create an image named MyCustomAMI from the EC2 instance CreateCustomAMI

  4. Check whether the image was created and click "Launch instance from AMI" button to create a new second EC2 instance:

  5. When launching a second EC2 instance UseCustomAMI , choose MyCustomAMI from My AMIs:

  6. During the launch of the second EC2 machine, add the following user data which writes a new file:

  7. Check whether the Apache server from custom AMI was installed by opening index.html file on the browser.


  1. Amazon Machine Images (AMI)