Building and Copying an AMI to Another Region
Published: 2022-01-13 11:25:45

AMI is an **Amazon Machine Image** provides the information needed to launch an EC2 instance in AWS, Which means An Amazon Machine Image(AMI) defines the programs and settings that will be applied when you launch an EC2 instance. In this Blog, it will renders the know-how about how to create a custom AMI and how to copy it into another region.

The below pictorial diagram throws light on the readers about AMI lifecycle. Once you create and register the AMI, you can use and launch the instance using that configuration. 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. 
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8qac801ou9yofc586vd.png)
 
Once you launch an instance from an AMI, you can connect to it. When you are connected to instance, you can use it just like you use any other server. 

You can launch an instance from an existing AMI, after this you got a thought to change the instance configuration (in-terms of installing a software, configuring ports, etc.) then you can save this configuration as a custom AMI. Now, this launched instance from an custom AMI includes the customisation that you made when you created an AMI. Now, you can use this as custom AMI for further uses. 

Here, You can create AMI in two ways:
1. Amazon EBS-backed AMI
2. Instance store-backed AMI

     First of all, you can create the AMI using the AWS management console or the command line. In this following will manuscript about the Amazon EBS-backed AMI and Instance store-backed AMI.

**1. Amazon EBS-Backed AMI:**
     
      Amazon EBS-backed AMI is can be create from an running EC2 instance. Here, it can be start from an existing AMI, launch an instance, customise it, and finally can launch an instance of your new AMI. 

      The following pictorial diagram will explain the entire process of creating an EBS-backed AMI;

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/908ffb86frlrklawdsxr.png)

**2. Instance Store-backed AMI:**

   The following picture shows the steps of how the instance store backed AMI is created. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/datj2ohp8ddq40rm3m8v.png)

   Here, First launch an instance from an AMI that is similar to your AMI which you would like to create. Connect the instance and customize it. When the instance is set up the way you want to create, you can bundle it. The creation of bundle will take several minutes to complete the process of bundling. Once it is completed, you have a bundle which consists of an image manifest (`image.manifest.xml`) and files (`image part`) which contains a template for root volume. For the root volume you can upload you bundle to the S3 bucket and then register your AMI. 

   Now, you can use this new AMI to launch an instance from it, and the root volume of an instance will be from  the bundle which is uploaded on S3 bucket for the same.

**Difference between EB-backed and instance store-backed AMI:**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0jihfgsaydfcbtgaj4o.png)


**

## Copying an AMI to Another Region 
** 

You can copy an Amazon Machine Image into to or another AWS region in two different ways; AWS Management Console, the AWS command Line Interface. You can copy both EBS-backed and instance store-backed AMI to Any region.

You can copy the image with Encrypted snapshots and it can be change during the process of copying. Copying a source AMI results in an identical target AMI but with it's own unique identifier. In case of EBS-backed AMI , each of it's supporting snapshots is by default copied to the destination but distinct target snapshot. The only exception for this case is when you choose to encrypt snapshot or encrypt it again. 

You can deregister the Source AMI without affecting the destination AMI. You can change or deregister it without any charge. The reverse is also true. There is no charge for copying an AMI but the standard data transfer and storage fees will be applied. 

The following picture shows that the relationship between a source AMI and two AMIs copied in different regions, as well as a instance launched from it. When you launch an instance from an AMI, it will reside the in the same region where the AMI resides. If you want to make the changes to the source AMI and want these changes reflected on the other side too then you must recopy the source AMIs to destination AMIs.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8u9p3gvr1ab1jdnm4eb.png)


> Now, let's walk through the process of an copying AMI to another region.

1. From the view of AMI of the AWS Management console select the AMI and click on copy.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xj8e6mwcecp3qh4bs5yd.png)
   
2. Choose the AMI operation and console will ask for the operation and destination where would you like to copy your AMI.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtox2meax4uhxn7lx85u.png)

3. After the changes and operation you have applied it will start copying it and result it the new AMI with the id in the destination region.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/588nvd4axcsq61quumn9.png)
  
Once the new AMI is available state the copy is completed.