How do I use VM Import/Export to create an Amazon EC2 instance based on my on-premises server?

Last updated: 2019-06-26

I’d like to create a copy of my on-premises server on AWS as an Amazon Elastic Compute Cloud (Amazon EC2) instance. How do I use VM Import/Export to do that?

Resolution

You can use the AWS Command Line Interface (AWS CLI) to run an VM Import/Export job. Then, a copy of your server is created as an Amazon Machine Image (AMI) and uploaded to an Amazon Simple Storage Service (Amazon S3) bucket. You can launch the AMI as an EC2 instance.

For large-scale migrations, AWS Server Migration Service (SMS) automates the migration process. You can import on-premises virtual machines running on VMware vSphere, Microsoft Hyper-V/SCVMM, and Azure.

Before getting started, do the following:

1.    Follow the guidelines to Prepare Your VM.

2.    Install the AWS CLI on an on-premises client and configure it with the AWS credentials generated for the VM import user.

3.    Create a new S3 bucket in the same AWS Region where you plan to run your EC2 instance.

4.    Create an IAM role named "vmimport" with the trust policy trust-policy.json that allows VM import service to assume the role.

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": { "Service": "vmie.amazonaws.com" },
         "Action": "sts:AssumeRole",
         "Condition": {
            "StringEquals":{
               "sts:Externalid": "vmimport"
            }
         }
      }
   ]
}

5.    Attach the following IAM policy named "vmimport" to the IAM role to grant permissions.

Note: Replace disk-image-file-bucket with your S3 bucket name.  

{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "s3:GetBucketLocation",
            "s3:GetObject",
            "s3:ListBucket" 
         ],
         "Resource":[
            "arn:aws:s3:::disk-image-file-bucket",
            "arn:aws:s3:::disk-image-file-bucket/*"
         ]
      },
      {
         "Effect":"Allow",
         "Action":[
            "ec2:ModifySnapshotAttribute",
            "ec2:CopySnapshot",
            "ec2:RegisterImage",
            "ec2:Describe*"
         ],
         "Resource":"*"
      }
   ]
}

6.    Upload the image to the S3 bucket with the tool of your choice.

7.    From the client machine, run the AWS CLI command import-image.

8.    To check the import task status, run the AWS CLI command describe-import-image-tasks.

9.    After the image is imported as an AMI, follow the instructions for Launching Your Instance from an AMI.