Image and Replicate Your Virtual Machine (AWS)

This is step 6 of 7 of Hands-On Project 1 for Amazon Web Services. In this step, you learn how to create an image of a fully-loaded virtual machine and create new virtual machines from the image, with pre-installed software. With these skills in hand, you can also confidently delete entire virtual machines and re-create them to save on usage costs.

Back to Project

To get a quick overview of how to image and replicate an EC2 instance, let’s start with this brief (6-minute) tutorial:

About Amazon Machine Images (AMIs)

On AWS, EC2 instances are created from Amazon Machine Images (AMIs). When you created your instance, you selected a standard AMI that Amazon makes available publicly. In addition to public AMIs, you can also create private AMIs that exist only within your AWS account. Once you have created a private AMI, you can then launch an EC2 instance from the private AMI.

Create an AMI of an Existing EC2 Instance

Assuming this instance is the one you created for the earlier steps, it will have software on it that you installed, such as the net-tools package, the python-is-python3 package, and the apache2 package. It will also have a user named ubuntu. All of this will be included in the private AMI when we create it.

To create a private AMI, perform the following steps:

  1. From the Management Console, complete the following steps:
  2. Navigate: Console Home –> EC2 –> Instances.
  3. On the row that contains the instance you want to image, right-click –> select Images and templates –> select Create Image.
  4. Enter an image name and an optional image description.
  5. Take the defaults for everything else and click Create Image. This will start the process of building the image — it will take a while before the image is available for use.
  6. On EC2 –> Instances, click on AMIs at the left. The image that you just created will likely be shown with a status of Pending. This status will change to Available when the image building process is complete.

Launch a new EC2 Instance from the Private AMI

Once the status of the image above becomes Available, you can launch a new EC2 instance from it. This will have the effect of cloning your original instance in the exact state it was in when you created the image.

To launch a new instance from a private AMI, perform the following steps:

  1. From the Management Console, complete the following steps:
  2. Navigate: Console Home –> EC2 –> AMIs.
  3. On the row containing the image you want to replicate, right-click and select Launch instance from AMI.
  4. The image you right-clicked on will be selected by default.
  5. For Instance Type, you can either use the same type as the original, or a different type. For this exercise, select t2.micro, which is the same as the original instance.
  6. For Key Pair (login), select the same key pair that you used for the original. The corresponding private key should reside within your Bitvise SSH client.
  7. For Network Settings, take the defaults for Network, Subnet, and Auto-assign IP address. You don’t want to use the Elastic IP that you created earlier because it is still in use on the original VM.
  8. For Firewall (security groups), you can create a new security group, or you can select the security group that already exists for the original EC2 instance. If you select the same security group, then any firewall rules you created will also be applied to the new instance.
  9. You can take the defaults for the remaining settings.
  10. Click on Launch Instance. This will start the provisioning process and in a few minutes, the cloned instance will be running.
  11. Connect to the new instance with Bitvise SSH client. If you used the same public SSH key as before, then the private key to access the new instance should already be there.

Once logged in, you can confirm whether the software you installed is there by running a few commands from the terminal window, such as:

sudo systemctl status apache2
python -V

These commands should work the same way they do on the original instance.