Migrate your own VMDK by uploading a snapshot in the AWS Console

When EC2 image-import does not work, import-snapshot can be used to import on AWS.
We will show you how to migrate an existing virtual server (vmdk) via snapshot. vmdk files that cause errors when creating an AMI can be created based on a snapshot as a way to force an AMI.
You can avoid the error process and set up an EC2 server based on a local vmdk file.

Upload vmdk file to S3

Upload the vmdk to the AWS storage service S3.
We assume that you already have the vmdk on hand; on ESXi, you can get the vmdk file by right-clicking on the target virtual server and exporting it.
You can upload the file to S3 by drag and drop on the web screen, which is a GUI operation.
Click Upload, select the file and press the Upload button to upload it.

Note the S3 URI, such as “s3://backet/test.vmdk".
This is so that the command can specify the S3 URI to move to the snapshot.

M1 mac to be able to use aws console

On a Mac, enter the following into the terminal and install it so that you can use aws console.

brew install awscli
aws configure

Set the AWS Access Key ID and AWS Secret Access Key or Default region name.
To obtain an Access Key ID and Secret Access Key, go to the AWS web page, select a user on the IAM screen, go to the Authentication Information tab, and click Create Access Key.

Configure IAM as vmimport role

Create a role that can import vmdk into AWS.
Create a trust-policy.json file and create the policy with the aws conwole command.

Create a trust-policy.json file with the vi command.

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

Create a role called vmimport.

aws iam create-role --role-name vmimport --assume-role-policy-document file://trust-policy.json

Create a policy and attach a role.

Create role-policy.json with the vi command.

vi role-policy.json
{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Action": [
            "s3:ListBucket",
            "s3:GetBucketLocation"
         ],
         "Resource": [
            "arn:aws:s3:::[Own bucket name]"
         ]
      },
      {
         "Effect": "Allow",
         "Action": [
            "s3:GetObject"
         ],
         "Resource": [
            "arn:aws:s3:::[Own bucket name]/*"
         ]
      },
      {
         "Effect": "Allow",
         "Action":[
            "ec2:ModifySnapshotAttribute",
            "ec2:CopySnapshot",
            "ec2:RegisterImage",
            "ec2:Describe*"
         ],
         "Resource": "*"
      }
   ]
}

Tie the role to the vmimport policy with a command in the AWS Console.

aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document file://role-policy.json

Convert S3 vmdk file to snapshot area

Create a json file to have asw console command. containers.json file.

vi containers.json
{
    "Description": "test.vmdk",
    "Format": "VMDK",
    "UserBucket": {
        "S3Bucket": "[Own bucket name]",
        "S3Key": "[File name to be specified].vmdk"
    }
}

Run the aws console command that reads containers.json.

aws ec2 import-snapshot --description "test.vmdk" --disk-container "file://containers.json"

You will get the following execution results.

{
    "Description": "test.vmdk",
    "ImportTaskId": "import-snap-xxxxxxxx",
    "SnapshotTaskDetail": {
        "Description": "test.vmdk",
        "DiskImageSize": 0.0,
        "Progress": "0",
        "Status": "active",
        "StatusMessage": "pending",
        "UserBucket": {
            "S3Bucket": "[Own bucket name]",
            "S3Key": "[File name to be specified].vmdk"
        }
    },
    "Tags": []
}

You can check the progress of the task with the describe-import-snapshot-tasks command, and if the Status is “completed", it is successful.

aws ec2 describe-import-snapshot-tasks --import-task-ids import-snap-xxxxxxxx
{
    "ImportSnapshotTasks": [
        {
            "Description": "test.vmdk",
            "ImportTaskId": "import-snap-xxxxxxxx",
            "SnapshotTaskDetail": {
                "Description": "test.vmdk",
                "DiskImageSize": 1069001216.0,
                "Format": "VMDK",
                "SnapshotId": "snap-xxxxxxxx",
                "Status": "completed",
                "UserBucket": {
                    "S3Bucket": "[Own bucket name]",
                    "S3Key": "[File name to be specified].vmdk"
                }
            },
            "Tags": []
        }
    ]
}

Create an image from a snapshot and create your own AMI

If it can be imported into AWS as a snapshot, the rest can be handled by manipulating it in the GUI environment.

Open the Elastic Block Store snapshot and you will find the snapshot you registered.
Select it and check it.

Select [Create Image from Snapshot].

Create an image by selecting an image name and architecture.
In this case, we created an image named test.

You have now created your own AMI.
EC2 will start up as usual, so you can set up your server as you like by selecting the AMI image you created from “My AMI" and choosing the instance type, etc.

Conclusion

In this article, we have shown how to convert your own VMDK file to a snapshot, create your own AMI image, and build an EC2 server. Now you can try to migrate your vmdk file onto AWS. If you are having trouble with errors using other methods, please try creating your own AMI image from a snapshot.