It is possible to migrate EC2 servers using Azure Migration or other tools but it can be an unnecessary workload for small organizations due to application installation requirements. So, I’ll describe how to migrate single VM to Azure using aws and az CLI with object storages.
Firstly, we’ll Log in to AWS console and create image for which server to be migrate.
Before start, you need extra permissions for VM Import/Export. Check link.
If its first snapshot, it would definitely take longer time. You can check image status from EC2
> Images
> AMIs
menu on left navigation.
We will need new or existing S3 bucket to export VHD image. If you don’t have please create one.
Then, we will use CloudShell on AWS console.
Use command below with update image-id and S3 Bucket parameters.
aws ec2 export-image --image-id ami-XXXXX --disk-image-format VHD \
--s3-export-location S3Bucket=myimage,S3Prefix=myexport
Output:
{
"DiskImageFormat": "VHD",
"ExportImageTaskId": "export-ami-XXXXX",
"ImageId": "ami-XXXXX",
"Progress": "0",
"S3ExportLocation": {
"S3Bucket": "myimage",
"S3Prefix": "myexport"
},
"Status": "active",
"StatusMessage": "validating"
}
Check Export Task status via CLI with ExportImageTaskId above.
aws ec2 describe-export-image-tasks \
--export-image-task-ids export-ami-XXXXX
Example output while converting.
{
"ExportImageTasks": [
{
"ExportImageTaskId": "export-ami-XXXXX",
"Progress": "85",
"S3ExportLocation": {
"S3Bucket": "myimage",
"S3Prefix": "myexport"
},
"Status": "active",
"StatusMessage": "converting",
"Tags": []
}
]
}
Completed after 3 hours of being stuck at 85% with converting status message for a 64 GB disk. After completion we are seeing VHD file with our prefix on S3 Bucket.
Now, download VHD file to upload Azure Blob. After that, we will create disk from VHD via az CLI. If you download file to same machine, you can upload using az storage command.
May be you need set policy to download. Check S3 Bucket Public Read Only Policy post.
az storage blob upload --account-name myimage \
--container-name mycontainer --name myvhd.vhd --file ./myvhd.vhd
Create vm from disk:
az vm create --resource-group rgName --name vmName --attach-os-disk diskName --os-type Linux
Thats all!