VM Import/Export
User Guide

Importing a Disk as a Snapshot Using VM Import/Export

VM Import/Export enables you to import your disks as Amazon EBS snapshots. After the snapshot is created, you can create an EBS volume from the snapshot, and then attach the volume to an EC2 instance.

Prerequisites

  • The following disk formats are supported: Virtual Hard Disk (VHD/VHDX), ESX Virtual Machine Disk (VMDK), and raw.

  • You must first upload your disks to Amazon S3.

  • If you have not already installed the AWS CLI, see the AWS Command Line Interface User Guide.

Start an Import Snapshot Task

Use the following import-snapshot command to import a disk. You can specify the URL of the S3 bucket, or provide the S3 bucket name and key.

aws ec2 import-snapshot --description "My server VM" --disk-container "file://C:\import\containers.json"

The file containers.json is a JSON document that contains required information.

{ "Description": "My server VMDK", "Format": "VMDK", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.vmdk" } }

The following is an example response:

{ "ImportTaskId": "import-snap-abcd1234", "SnapshotTaskDetail": { "DiskImageSize": "0.0", "Progress": "3", "Status": "active", "Description": "My server VMDK", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.vmdk" }, "StatusMessage": "pending" }, "Description": "My server VM" }

Monitor the Import Snapshot Task

Use the describe-import-snapshot-tasks command to check the status of an import snapshot task.

aws ec2 describe-import-snapshot-tasks --import-task-ids import-snap-abcd1234

The following is an example response. The status shown is active, which means the import is in progress. The snapshot is ready to use when the status is completed.

{ "ImportSnapshotTasks": [ { "SnapshotTaskDetail": { "DiskImageSize": "3.115815424E9", "Progress": "22", "Status": "active", "Description": "My server VMDK", "Format": "VMDK", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.vmdk" }, "StatusMessage": "Validated" }, "ImportTaskId": "import-snap-abcd1234", "Description": "My server VM" } ] }

Cancel an Import Snapshot Task

If you need to, you can cancel an import task that is in progress.

To cancel a snapshot import task

  1. Use the describe-import-snapshot-tasks command to determine the ID of the import task to cancel.

    aws ec2 describe-import-snapshot-tasks
  2. Cancel the task with cancel-import-task command.

    aws ec2 cancel-import-task --import-task-id "import-snap-abcd1234"

Next Steps

You can create one or more EBS volumes from an EBS snapshot. You can attach each EBS volume to a single EC2 instance.

The following procedure shows how to create a volume and attach it to an instance using the AWS CLI. Alternatively, you could use the AWS Management Console.

To create a volume and attach it to an EC2 instance

  1. Use the describe-import-snapshot-tasks command to determine the ID of the snapshot that was created by the import task.

  2. Use the following create-volume command to create a volume from the snapshot. You must select the Availability Zone of the instance to which you'll attach the volume.

    aws ec2 create-volume --availability-zone us-east-1a --snapshot-id snap-1234567890abcdef0

    The following is example output:

    { "AvailabilityZone": "us-east-1a", "VolumeId": "vol-1234567890abcdef0", "State": "creating", "SnapshotId": "snap-1234567890abcdef0" }
  3. Use the following attach-volume command to attach the EBS volume that you created in the previous step to one of your existing instances.

    aws ec2 attach-volume --volume-id vol-1234567890abcdef0 --instance-id i-1234567890abcdef0 --device /dev/sdf

    The following is example output:

    { "AttachTime": "YYYY-MM-DDTHH:MM:SS.000Z", "InstanceId": "i-1234567890abcdef0", "VolumeId": "vol-1234567890abcdef0", "State": "attaching", "Device": "/dev/sdf" }
  4. Mount the attached volume. For more information, see the documentation for the operating system for your instance.