VM Import/Export to AWS

By: Willio Jean Paul

Overview

This will take you to the steps to create a copy of an on-premises server on AWS as an Amazon Elastic Compute Cloud (EC2) instance.  We will use the AWS Command Line Interface (AWS CLI) to run a VM Import/Export job.  Upon completion, a copy of the server is created as an Amazon Machine Image (AMI) and uploaded to an Amazon Simple Storage Service (Amazon S3) bucket. 

Tasks Outline

  1. Follow the guidelines to Prepare Your VM
  2. Install the AWS CLI and configure credentials
  3. Create a new S3 bucket in the same AWS region where you will run the EC2 instance
  4. Create  an IAM role named “vmimport” with trust policy trust-policy.json that allows the VM import service to assume the role.

    4.1. Create the file “trust-policy.json” with the content below using your favorite text editor:

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


    4.2. Create the role using the aws cli command below:
    aws iam create-role --role-name vmimport --assume-role-policy-document “file://trust-policy.json"
  5. Attach the following IAM policy named “vmimport” to the IAM role to grant permissions.

    5.1. Create the file “role-policy.json” with the content below using your favorite text editor:

    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Effect": "Allow",
    "Action": [
    "s3:GetBucketLocation",
    "s3:GetObject",
    "s3:PutObject"
    ],
    "Resource": ["arn:aws:s3:::disk-image-bucket-testing",
    "arn:aws:s3:::disk-image-bucket-testing/*"]
    },
    {
    "Effect": "Allow",
    "Action": [
    "ec2:CancelConversionTask",
    "ec2:CancelExportTask",
    "ec2:CreateImage",
    "ec2:CreateInstanceExportTask",
    "ec2:CreateTags",
    "ec2:ExportImage",
    "ec2:ImportInstance",
    "ec2:ImportVolume",
    "ec2:StartInstances",
    "ec2:StopInstances",
    "ec2:TerminateInstances",
    "ec2:ImportImage",
    "ec2:ImportSnapshot",
    "ec2:CancelImportTask",
    "ec2:Describe*"
    ],
    "Resource": "*"
    }
    ]
    }


    5.2. Attach the policy using the  aws cli command below:
    aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document “file://role-policy.json”

  6. Upload the image to the S3 bucket using the aws cli command:

    aws s3 cp SIFT-Workstation.ova s3://disk-image-file-bucket-testing/

    Confirm that the image has been uploaded successfully by using the listing command
    aws s3 ls s3://disk-image-file-bucket-testing/
  7. From the client machine, create the file “containers.json” and run the AWS CLI command import-image to start the import.

    7.1. Create the file “containers.json” with the content below using your favorite text editor:

    [
    {
    "Description": "SIFT Workstation OVA",
    "Format": "ova",
    "UserBucket": {
    "S3Bucket": "disk-image-file-bucket-testing",
    "S3Key": "sift-workstation.ova"
    }
    }
    ]

    7.2 . Run the aws command to import the image
    aws ec2 import-image --description “SIFT Workstation OVA - $(date)”” --disk-containers file://containers.json

  8. To check the import task status, run the AWS CLI command describe-import-image-tasks.
    aws ec2 describe-import-image-tasks --import-task-ids import-ami-0d34054c26c9b342c

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


Reference:

  1. VM Import/Export Requirements: https://docs.aws.amazon.com/vm-import/latest/userguide/vmie_prereqs.html
  2. Required Permission for IAM Users: https://docs.aws.amazon.com/vm-import/latest/userguide/vmie_prereqs.html#iam-permissions-image
  3. Import Your VM as an Image: https://docs.aws.amazon.com/vm-import/latest/userguide/vmimport-image-import.html#import-vm-image
  4. Creating an IAM User in Your AWS Account: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html
  5. Access Keys (Access Key ID and Secret Access Key): https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys
  6. Amazon Machine Images (AMI): https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html

Subscribe

Stay in the loop! Sign up for our newsletter today for getting regular updates.