Skip to content

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

3 minute read
0

I want to create a copy of my on-premises server on AWS as an Amazon Elastic Compute Cloud (Amazon EC2) instance using VM Import.

Resolution

You can use the AWS Command Line Interface (AWS CLI) to run a 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.

Note: If you receive errors when you run AWS CLI commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Before getting started, do the following:

Then, complete the following steps:

  1. Follow the guidelines in Required configuration for VM export.

  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 the 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": "*"
        }
      ]
    }

    Note: The ec2:Describe* action uses a wildcard to include all EC2 Describe operations required by the VM Import/Export process. The "Resource": "*" is required because EC2 Describe actions don't support resource-level permissions. To follow the principle of least privilege, replace ec2:Describe* with only the specific Describe actions your import job requires, such as ec2:DescribeImportImageTasks and ec2:DescribeImages.

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

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

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

  9. After the image is imported as an AMI, follow the instructions for Launch an Instance using the old launch instance wizard. Or, follow the instructions for Launch an instance using the new launch instance wizard.

Related information

Import a VM to Amazon EC2 as an image using VM Import/Export

Creating an IAM user in your AWS account

AWS security credentials

Amazon Machine Images in Amazon EC2

AWS OFFICIALUpdated 6 years ago