Migrating Azure/Hyper-V Virtual Machine to AWS using AWS VM Import/Export (AWS PowerShell) – Part 1 of 3

While the cloud adoption is on its peak, Migrating different kind of workloads from on-premises datacenter to Cloud or Cloud to Cloud is common task for IT professionals. In this blog post I will discuss and guide about step by step Virtual Machine migration from Azure/Hyper-V environment to AWS Cloud using AWS native tool called VM Import/Export.

There are different tools available in the market that can one can use to migrate to AWS Cloud, below are the tools provided by AWS. In this blog post I will be talking about VM Import/Export migration tool.

  1. AWS VM Import/Export (VMIE)
  2. AWS SMS (Server Migration Service)
  3. CloudEndure (https://www.cloudendure.com/)

What is AWS VM Import/Export?
VM Import/Export helps you to import Virtual Machine images from your on-premises environment (Hyper-V/VMware) or other cloud platforms (like Azure) to AWS Cloud. This tool is natively provided in AWS CLI and AWS PowerShell module and is fully supported by AWS. There is no additional costing involved with this tool

VM Import/Export Prerequisites:
Please see the below official AWS document for VM Import/Export Prerequisites:
https://docs.aws.amazon.com/vm-import/latest/userguide/vmie_prereqs.html
Along with the prerequisites mentioned in the above documentations, I would briefly point out some key requirements below:

1. If you don’t have AWS PowerShell installed and configured on your machine the please follow below document to configure AWS PowerShell. https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up-windows.html
https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html

2. VM Import/Export service requires IAM role “vmimport” to perform some operations like Image registration, snapshot copy and downloading disk images from the S3 bucket. I have created a VM Import Service role in IAM with administrator access (though it doesn’t require administrator access) with Inline Policy attached like below.

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: [
“s3:GetBucketLocation”,
“s3:GetObject”,
“s3:ListBucket”
],
“Resource”: [
“arn:aws:s3:::singhajeet”,
“arn:aws:s3:::singhajeet/
]
},
{
“Effect”: “Allow”,
“Action”: [
“ec2:ModifySnapshotAttribute”,
“ec2:CopySnapshot”,
“ec2:RegisterImage”,
“ec2:Describe
],
“Resource”: “*”
}
]
}

3. Create S3 bucket where you would like to upload Virtual Machine disk images. I have below S3 bucket in “US-EAST-1” region where I will be uploading my VM Images

Migration Steps:
Now let’s start migrating our Azure VM to AWS Cloud.
1. I have following Virtual Machine in Azure that I will be migrating to AWS.

2. I turned off the Azure Virtual Machine and downloaded the VHD on my local machine. There are various method you can use to download Azure VM disks. I used Azure Storage Explorer tool.
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/download-vhd
https://azure.microsoft.com/en-in/features/storage-explorer/

3. Now I have the VHD downloaded to local machine.

4. I assume that you have setup AWS PowerShell on your machine successfully, I have following S3 buckets in my account. I will be uploading VM Images to “singhajeet” bucket.

4. I ran below command to initiate VHD upload to my S3 bucket. The file upload to S3 bucket will happen over internet so based on your network bandwidth and image size it will require some time to complete the upload.
Write-S3Object –BucketName singhajeet –File “C:\Temp\AzVMVHD\AWSMigration.vhd”

5. Now I have my VM Image uploaded to S3 bucket successfully

6. Now run the below commands in sequence, here I’m creating disk container and S3 bucket objects and storing property values

 $bucketName = “singhajeet”
 $DiskContainer = New-Object Amazon.EC2.Model.ImageDiskContainer  $DiskContainer.Format=”VHD”  
$Bucket = New-Object Amazon.EC2.Model.UserBucket
 $Bucket.S3Bucket = $bucketName
 $Bucket.S3Key = “AWSMigration.vhd”
 $DiskContainer.UserBucket = $Bucke

7. Now create below hash table to pass the parameters that is required for the cmdlet “Import-EC2Image” that will be executing next to start the image import process

    $params = @{
    “ClientToken”=”AWSMigration_” + (Get-Date)
    “Description”=”My Azure VM”
    “Platform”=”Windows”
    “LicenseType”=”AWS”
}

Note: When migrating to your on-premises Virtual Machine or Azure VM to AWS, you have to decide whether you would like to use your own license (BYOL) or license provided by AWS. Based on your choice you can specify the option above in “LicenseType” parameter. If you specify AWS as license type then your VM cost will include licensing cost as well.

8. Now run the below command to initiate image import process.
Import-EC2Image -DiskContainer $DiskContainer @param

Note: You must have an IAM role “vmimport” with appropriate permissions, in case you have created this IAM role with some other name then you need to specify “-RoleName” parameter with this command.
https://docs.aws.amazon.com/powershell/latest/reference/Index.html

9. Now image import process is initiated, you can run below cmdlet to check the status of the image import task. Now we can see our image import task is converting the image to EBS volume.

Get-EC2ImportImageTask

10. VM image import process goes through various phases, so if you keep running below cmdlet after some interval you can track your image import task. Now we can see our import task is at “booting” phase.

11. If you see now the status of the task is “booted” means it has successfully completed the image import process, after this stage it will be creating an Amazon Machine Image (AMI) for me.

12. Now I have my AMI created successfully for imported VM image.

13. I launched an instance from this AMI and I verified that everything is working as expected.

Note: EC2 instances that created by the imported image AMI can always be exported back to your on-premises virtualization environment. EC2 instance created using Amazon provided AMI can’t be exported and used in on-premises environment.

You can review below troubleshooting documentation for VM Import/Export which will help us to investigate import task failure.
Troubleshooting VM Import Export:
https://docs.aws.amazon.com/vm-import/latest/userguide/vmimport-troubleshooting.html

Note: Mostly I have seen issues occurring at “booting” stage because of any driver issues or due to some networking configuration or if the AWS Network related drivers was not installed.

What’s next – I will be posting Part 2 of this series in next post covering some other migration scenarios. This post was focused on migrating Azure/Hyper-V VM with single disk. I will be covering multi disk migration with VMware based Virtual Machines in next blog post.

I hope you will be find this helpful. Happy learning!!!

5 thoughts on “Migrating Azure/Hyper-V Virtual Machine to AWS using AWS VM Import/Export (AWS PowerShell) – Part 1 of 3”

  1. Hi Ajeet,
    Thanks for detailed article on Migrating the on-Premises workload to AWS.It would be good if you also mention what type of disk, max os disk size, max data disk size and disk format AWS supports.
    Thanks,
    Satish K

    1. Thanks for the comment Satish. Yes, your question is valid. I felt the list for supported OS and supported disk format, max disk size etc. was little long so instead of listing them here I linked the prerequisites documentation link in the blog hoping that it will help.

  2. Thanks for finally talking about >Migrating Azure/Hyper-V Virtual Machine to AWS using
    AWS VM Import/Export (AWS PowerShell) – Part 1 of 3 – A Place where cloud begins….

    <Loved it!

Leave a Reply

Your email address will not be published.