AWS Custom AMI – How To Create & Launch a Instance



Hi There, today we will discuss some key points about AWS AMI, how to create and launch an instance.

So let’s start.. ( Here I have focused in windows instance )

  • Stands for Amazon Machine Images (AMI)
  • There are two types of AMI: AWS Managed & Customer Managed
  • When you launch an instance from a Windows AMI, the root device for the Windows instance is an Amazon Elastic Block Store (Amazon EBS) volume. Windows AMIs do not support instance store for the root device. 
  • Windows Server 2003 does not support AWS AMI as it’s already deprecated by Microsoft
  • AWS provides updated, fully-patched Windows AMIs within five business days of Microsoft’s patch Tuesday (the second Tuesday of each month).The AWS Windows AMIs contain the latest security updates available at the time they were created.
  • AMIs use one of two types of virtualization: paravirtual (PV) or hardware virtual machine (HVM) and Windows AMIs are HVM AMIs. 
  • AMI can be customised using EC2Config service (2012 r2 or earlier) OR EC2Launch (Windows Server 2016 and later)
  • You can subscribe to windows AMI notification using SNS to be notified when new AMIs are released or when previously released AMIs are made private 
  • Changes in Windows Server 2016 and later AMIs, such as :Accommodate the change from .NET Framework to .NET Core, the EC2Config service has been deprecated and replaced by EC2Launch
  • If you plan to run Docker on a Windows Server 2016 instance, you must create the instance from the following Amazon Machine Image (AMI) or an AMI based on an image with Windows_Server-2016-English-Full-Containers in the name. Otherwise, if you use a different Windows Server 2016 AMI, instances fail to boot correctly after installing Docker and then running Sysprep. 

Create a custom Windows AMI

You can launch an instance from an existing Windows AMI, customize 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. 

To categorize and manage your AMIs, use custom tags

How the creation of a custom AMI works

  • First, launch an instance from an AMI that’s similar to the AMI that you’d like to create.
  • connect to your instance and customize it. When the instance is set up the way you want it, ensure data integrity by stopping the instance before you create an AMI and then create the image. 
  • During the AMI-creation process, Amazon EC2 creates snapshots of your instance’s root volume and any other EBS volumes attached to your instance. You’re charged for the snapshots until you deregister the AMI and delete the snapshots
  • AMI creation time depends on the EBS volume size
  • After the process completes, you have a new AMI and snapshot created from the root volume of the instance. When you launch an instance using the new AMI, aws create a new EBS volume for its root volume using the snapshot. 

       High Level Diagram

Steps to Create a Custom AMI

Navigate to EC2 console, then Launch a 2019 instance using following aws managed AMI(you can take other OS type)

Below is the current status of the instance and we havn’t done any customization on it.

Now we will install a few software ( like Chrome, Git) and create a few folders in C:\ as shown below

Now before we create an image, it’s recommended to STOP the instance to ensure data integrity.

So let’s STOP the instance.

Create the Image

Select the instance, then go to Action –> Image and Templates and click Create Image

Fill the Image Name and Description, and leave everything as it is for now and click Create Image

Now go to AMI section, there you will see you image being created

After some time..

Please note that in the backend there is a snapshot created associated with this AMI, that you can verify in the snapshot section as shown below.

Now lets terminate our instance (server-1) and launch a fresh one using our custom image.

Launch instance from custom AMI

Go to AMI section and select the custom AMI and click Launch

Follow the default steps while launching the instance as you do normally and complete.

Now you can see our new instance (server -2)  from our custom AMI has been up and running.

Now we will login and verify the softwares and folders we have created are present.

Note: Please use administrator/user credentials from where the image was created to login. This is for a technical reason , will discuss about it in next blog about AMI.

Please see below, everything we installed and created is present as expected.

So this is it guys for now, there are more points to learn about AMI so we will discuss in following blog posts.

Till then bye!! Take care..