Importing a Virtual Machine into Amazon EC2 (Part 7)

If you would like to read the other parts in this article series please go to:

In my previous article, I showed you how to export a Hyper-V virtual machine so that the VM could be imported into the Amazon cloud. In this article, I want to continue the discussion by showing you how the import process works.

So before I get started, I need to once again mention that the method that you will be using to import the VM will vary depending on your on premise virtualization infrastructure. If you are using VMware locally then the import process is relatively intuitive. Amazon has some nice tools for importing VMware VMs. If on the other hand, you are importing a Hyper-V VM like I am then the process can be a bit intimidating. But don’t worry, you are in good hands and I will walk you through the process and keep the explanation as simple as I possibly can.

If you think back to the earlier articles in this series, you may recall that I walked you though the process of installing the Amazon Command Line Interface. We are going to be using this interface to create the import task.

Before I show you how to do this, I want to be sure to pass along a few recommendations that Amazon makes regarding your VM instance. First, Amazon will automatically assign a DHCP based IP address to the VM after the import process is completed. This behavior is probably to be expected, but there are two things that you need to be aware of. First, your VM will only have a single network interface. Second, It’s a good idea to familiarize yourself with the EC2-Describe-Instances command since this command is used to get information on the DNS name and IP address used by the instance.

Amazon also makes some recommendations with regard to security. Windows VMs are recommended to have strong passwords and Linux VMs should be using public keys for SSH.

Finally, Amazon recommends that you install the most recent version of Amazon Windows EC2Config Service onto any Windows VMs after the import process has completed.

So with that said, let’s talk about the import process. Importing a VM into Amazon EC2 requires you to create an import instance task. This task can be performed by entering a single command. The command is:

$ aws ec2 import-image –cli-input-json “{  \”Description\”: \”Windows 2008 OVA\”, \”DiskContainers\”: [ { \”Description\”: \”First CLI task\”, \”UserBucket\”: { \”S3Bucket\”: \”my-import-bucket\”, \”S3Key\” : \”my-windows-2008-vm.ova\” } } ]}”

The most important parts of the command shown above are the description and the reference to the virtual disk image. In this particular case I took the command directly from the Amazon documentation and the command references an OVA based virtual hard disk. This virtual hard disk type is commonly associated with VMware. If you are importing a Hyper-V based virtual disk then you would instead reference a VHD or a VHDX file.

When you enter the command shown above, you will receive a response that includes several lines of XML code. The example response provided by Amazon is:

<ImportImageResponse xmlns=”http://ec2.amazonaws.com/doc/2015-03-01/”>

<progress>2</progress>

<importTaskId>import-ami-fgxn195v</importTaskId>

<status>active</status>

<description>Windows 2008 OVA</description>

<snapshotTaskDetailSet>

<item>

<diskImageSize>0.0</diskImageSize>

<userBucket>

<s3Bucket>my-import-bucket</s3Bucket>

<s3Key>my-windows-2008-vm.ova</s3Key>

</userBucket>

</item>

</snapshotTaskDetailSet>

<licenseType>AWS</licenseType>

<statusMessage>pending</statusMessage>

<requestId>1571e127-d6d8-4984-b4f1-3a21e9dbdcb5</requestId>

</ImportImageResponse>

One thing to keep in mind about the import process is that the import can take some time to complete. After all, the virtual hard disk has to be uploaded and then Amazon has to convert it into something that the service can use. This can be a somewhat time consuming process and you will probably want to periodically check to see how the process is progressing.

If you want to check the status of the import image task then you will have to once again used the command line. The Amazon documentation provides the following command that you can use when checking the status of the import task:

$ aws ec2 describe-import-image-tasks –cli-input-json “{ \”ImportTaskIds\”: [\”import-ami-fgxn195v\”], \”NextToken\”: \”abc\”, \”MaxResults\”: 10 } “

Once again, Amazon provides an example response that consists of a block of XML code. The example response is:

<DescribeImportImageTasksResponse xmlns=”http://ec2.amazonaws.com/doc/2015-03-01/”>

<importImageTaskSet>

<item>

<platform>Windows</platform>

<importTaskId>import-ami-fgs8im0c</importTaskId>

<imageId>ami-4a6c2722</imageId>

<status>completed</status>

<description>Linux OVA</description>

<architecture>x86_64</architecture>

<snapshotTaskDetailSet>

<item>

<diskImageSize>3.115815424E9</diskImageSize>

<deviceName>/dev/sda1</deviceName>

<description>First CLI task</description>

<format>VMDK</format>

<url>https://mys3bucket/vms/my-linux-vm.ova?AWSAccessKeyId=myAccessKeyId&Expires=expirationDate&Signature=mySignature</url>

</item>

</snapshotTaskDetailSet>

<licenseType>AWS</licenseType>

</item>

</importImageTaskSet>

<requestId>377ec1ca-6a47-42f5-8b84-aa07ff87f7b0</requestId>

</DescribeImportImageTasksResponse>

At first glance, this block of code probably seems like overkill since the goal is simply to determine whether or not the task has completed. Even so, there are a few things in this sample code block that are worth paying attention to.

First, you will notice that there are fields labeled Platform, Description and Architecture. The reason why these fields are important is because they can help you to identify the import task. While this might at first seem unnecessary, keep in mind that there may be multiple import tasks being run at the same time. If you look at the command that is used for checking the import status, you will notice that it includes a parameter that sets the MaxResults to 10. In other words, the command could potentially display up to 10 different import tasks and the Platform, Description, and Architecture fields can help you to differentiate between the various tasks.

The other thing that is important to pay attention to is the Status line. Here is what the line looks like in the example code listed above:

<status>completed</status>

In this particular case the status is Completed, which of course means that the import process has been completed and the import image is ready to use. However, Completed is not the only possible status. Other status indicators include:

Active – The task is being processed right now

Deleting – The task is about to be canceled

Deleted – The task has been canceled

Once the task has been completed then you should be able to launch an Amazon EC2 instance that is based on the file that you have imported. Thankfully, this is easy to do. Simply open the Amazon EC2 console and then choose the AMIs option from the navigation pane. Now select the AMI that you just imported and click the Launch button.

What About the Amazon Windows EC2 Config Service?

Earlier I mentioned that Amazon recommends installing the Amazon Windows EC2 Config Service. You can download the service here. The best way that I can think of to describe these services is to compare them to the Hyper-V Integration Services or to the VMware Tools. Microsoft and VMware both provide a set of drivers (the Hyper-V Integration Services and the VMware Tools) that allow a VM to better interact with the hypervisor. The Amazon Windows EC2 Config Service performs a somewhat similar function for Windows VMs running in the Amazon cloud. It handles things like Windows activation, setting the administrator password, and so on. In order to install this service the VM must be running version 3.5 SP1 or higher of the .NET Framework.

Conclusion

As you can see, it really isn’t very difficult to import a VM into Amazon EC2. The entire import process can be handled through a single command. Even so, there is a lot of prep work required in order to prepare your VM for a cloud migration.

If you would like to read the other parts in this article series please go to:

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top