Importing a disk as a snapshot using VM Import/Export - VM Import/Export

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.

An imported snapshot has an arbitrary volume ID that should not be used for any purpose.

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 on the computer you'll use to run the import commands, see the AWS Command Line Interface User Guide.

    Tip

    In supported AWS Regions, you can also use AWS CloudShell for a browser-based, pre-authenticated shell that launches directly from the AWS Management Console.

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 the 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:

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

Monitor an 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-1234567890abcdef0

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

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

Cancel an import snapshot task

If you need to, you can cancel an import task that is in progress using the cancel-import-task command.

aws ec2 cancel-import-task --import-task-id import-snap-1234567890abcdef0

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.