

# Import a VM to Amazon EC2 as an image using VM Import/Export
<a name="vmimport-image-import"></a>

**Tip**  
To import your virtual machines (VMs) with a console-based experience, you can use the *Import virtual machine images to AWS* template in the [Migration Hub Orchestrator console](https://console.aws.amazon.com/migrationhub/orchestrator). For more information, see the [https://docs.aws.amazon.com/migrationhub-orchestrator/latest/userguide/import-vm-images.html](https://docs.aws.amazon.com/migrationhub-orchestrator/latest/userguide/import-vm-images.html).

You can use VM Import/Export to import virtual machine (VM) images from your virtualization environment to Amazon EC2 as Amazon Machine Images (AMI), which you can use to launch instances. Subsequently, you can export the VM images from an instance back to your virtualization environment. This enables you to leverage your investments in the VMs that you have built to meet your IT security, configuration management, and compliance requirements by bringing them into Amazon EC2.

**Topics**
+ [Export your VM from its virtualization environment](export-vm-image.md)
+ [Programmatic modifications made to VMs by VM Import/Export](import-modify-vm.md)
+ [Import your VM as an image](import-vm-image.md)
+ [Monitor an import image task](check-import-task-status.md)
+ [Cancel an import image task](cancel-upload.md)
+ [Create an EC2 instance from an imported image](import-vm-next-steps.md)

# Export your VM from its virtualization environment
<a name="export-vm-image"></a>

After you have prepared your VM for export, you can export it from your virtualization environment. When importing a VM as an image, you can import disks in the following formats: Open Virtualization Archive (OVA), Virtual Machine Disk (VMDK), Virtual Hard Disk (VHD/VHDX), and raw. With some virtualization environments, you would export to Open Virtualization Format (OVF), which typically includes one or more VMDK, VHD, or VHDX files, and then package the files into an OVA file.

For more information, see the documentation for your virtualization environment. For example:
+ **VMware** — Search for "Export an OVF Template" on the [VMware Docs](https://docs.vmware.com/) site. Follow the instructions to export an OVA.
+ **Citrix** — [Importing and Exporting VMs](https://docs.citrix.com/en-us/xencenter/current-release/vms-exportimport.html) on the Citrix website.
+ **Microsoft Hyper-V** — [Overview of exporting and importing a virtual machine](https://technet.microsoft.com/en-us/library/hh831535.aspx) on the Microsoft website.
+ **Microsoft Azure** — [Download a Windows VHD from Azure](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/download-vhd) or [Download a Linux VHD from Azure](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/download-vhd) on the Microsoft website. From the Azure Portal, choose the VM to migrate, and then choose **Disks**. Select each disk (either OS or data) and choose **Create Snapshot**. On the completed snapshot resource, choose **Export**. This creates a URL that you can use to download the virtual image.

# Programmatic modifications made to VMs by VM Import/Export
<a name="import-modify-vm"></a>

When importing a VM using the `ImportImage` API, AWS modifies the file system and adds drivers to make the imported VM bootable. When writing a modified file, AWS retains the original file at the same location under a new name. The following actions may occur:

**General**
+ For parity with images provided by AWS, the AWS Systems Manager client is installed on the VM.

**Windows**
+ Modifying registry settings to make the VM bootable.

**Linux**
+ Installing Citrix PV drivers either directly in OS or modify initrd/initramfs to contain them.
+ Modifying network scripts to replace static IPs with dynamic IPs.
+ Modifying `/etc/fstab`, commenting out invalid entries and replacing device names with UUIDs. If no matching UUID can be found for a device, the `nofail` option is added to the device description. You must correct the device naming and remove `nofail` after import. As a best practice when preparing your VMs for import, we recommend that you specify your VM disk devices by UUID rather than device name.

  Entries in `/etc/fstab` that contain non-standard file system types (cifs, smbfs, vboxsf, sshfs, etc.) are disabled.
+ Modifying grub bootloader settings such as the default entry and timeout.

## Import VM without modifications
<a name="import-without-modifications"></a>

If you need to import a VM without programmatic modifications, we recommend that you follow these steps instead of using `ImportImage`.

**Important**  
If you use this process, AWS does not do any post-import validations to ensure that the image is bootable. It is your responsibility to ensure that you properly prepare your VM for exporting.

**To import a VM without modifications**

1. Prepare your VM for export. For more information, see [Configurations to export VMs from your virtualization environment](prepare-vm-image.md).

1. Export the boot disk for your VM in one of the following file formats: VHD/VHDX, VMDK, or raw. For more information, refer to the documentation for your virtualization environment.

1. Use the [ put-object](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-object.html) command to upload the exported boot disk file to an Amazon S3 bucket in the Region where you want to create the image.

1. Use the [ import-snapshot](https://docs.aws.amazon.com/cli/latest/reference/ec2/import-snapshot.html) command to import the boot disk as a snapshot. For more information about importing a snapshot, see [Import a disk as an EBS snapshot using VM Import/Export](vmimport-import-snapshot.md).
**Note**  
You can monitor the progress of the import snapshot task using the [ describe-import-snapshot-tasks](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-import-snapshot-tasks.html) command.

   Make a note of the snapshot ID returned by the command. You'll need it for the next step.

1. Use the [ register-image](https://docs.aws.amazon.com/cli/latest/reference/ec2/register-image.html) command to register a new AMI, and specify the snapshot from the previous step as the root device volume.

   Make a note of the image ID returned by the command. You'll need it for the next step.

1. After the AMI reaches the `available` state, you can use it to launch instances.

# Import your VM as an image
<a name="import-vm-image"></a>

After exporting your VM from your virtualization environment, you can import it to Amazon EC2 using VM Import/Export. The import process is the same regardless of the origin of the VM.

**Topics**
+ [Prerequisites for importing a VM into Amazon EC2](#import-image-prereqs)
+ [Upload the image to Amazon S3](#upload-image)
+ [Import the VM](#import-vm)

## Prerequisites for importing a VM into Amazon EC2
<a name="import-image-prereqs"></a>
+ Create an Amazon Simple Storage Service (Amazon S3) bucket for storing the exported images or choose an existing bucket. The bucket must be in the Region where you want to import your VMs. For more information about S3 buckets, see the [Amazon Simple Storage Service User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/).
+ Create an IAM role named `vmimport`. For more information, see [Required service role](required-permissions.md#vmimport-role).
+ 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](https://docs.aws.amazon.com/cli/latest/userguide/).
**Tip**  
In [supported AWS Regions](https://docs.aws.amazon.com/cloudshell/latest/userguide/supported-aws-regions.html), you can also use [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html) for a browser-based, pre-authenticated shell that launches directly from the AWS Management Console.

## Upload the image to Amazon S3
<a name="upload-image"></a>

Upload your VM image file to your S3 bucket using the upload tool of your choice. For information about uploading objects through the Amazon S3 console, see [Uploading Objects](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html).

## Import the VM
<a name="import-vm"></a>

After you upload your VM image file to Amazon S3, you can use the AWS CLI to import the image. These tools accept either the S3 bucket and path to the file or a URL for a public Amazon S3 file. Private Amazon S3 files require a [presigned URL]( https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html).

You can also use the *Import virtual machine images to AWS template* in the [Migration Hub Orchestrator](https://console.aws.amazon.com/migrationhub/orchestrator/) console to import your on-premises virtual machine images to AWS. For more information, see [Example 4: Import an image using Migration Hub Orchestrator](#import-vm-mho).

**Important**  
AWS VM Import/Export strongly recommends specifying a value for either the `--license-type` or `--usage-operation` parameter when you create a new VM Import task. This ensures your operating system is licensed appropriately and your billing is optimized. For more information, see [Licensing for your imported VMs](licensing.md).
AWS VM Import/Export only supports images that were natively installed inside the source VM and not those created using a physical-to-virtual (P2V) conversion process. For more information, see the [VM Import/Export Requirements](vmie_prereqs.md).

**Topics**
+ [Example 1: Import an image using an OVA file](#import-vm-single-disk)
+ [Example 2: Import an image with multiple disks](#import-vm-multi-disk)
+ [Example 3: Import with the encrypted option enabled](#import-vm-encrypted)
+ [Example 4: Import an image using Migration Hub Orchestrator](#import-vm-mho)

### Example 1: Import an image using an OVA file
<a name="import-vm-single-disk"></a>

------
#### [ AWS CLI ]

Use the following [https://docs.aws.amazon.com/cli/latest/reference/ec2/import-image.html](https://docs.aws.amazon.com/cli/latest/reference/ec2/import-image.html) command.

```
aws ec2 import-image \
    --description "$(date '+%b %d %H:%M') My server VM" \
    --license-type "AWS" \
    --disk-containers '[{
    "Format": "OVA",
    "UserBucket": {
      "S3Bucket": "amzn-s3-demo-import-bucket",
      "S3Key": "vms/my-server-vm.ova"
    }
  }]'
```

------
#### [ PowerShell ]

Use the [Import-EC2Image](https://docs.aws.amazon.com/powershell/latest/reference/items/Import-EC2Image.html) cmdlet as follows.

```
Import-EC2Image `
    -Description ((Get-Date -Format "MMM dd HH:mm ") + "My server OVA") `
    -LicenseType "AWS" `
    -DiskContainer @(
        @{
            Format = "OVA"
            UserBucket = @{
                S3Bucket = "amzn-s3-demo-import-bucket"
                S3Key = "vms/my-server-vm.ova"
            }
        }
    )
```

------

### Example 2: Import an image with multiple disks
<a name="import-vm-multi-disk"></a>

------
#### [ AWS CLI ]

Use the [https://docs.aws.amazon.com/cli/latest/reference/ec2/import-image.html](https://docs.aws.amazon.com/cli/latest/reference/ec2/import-image.html) command.

```
aws ec2 import-image \
    --description "$(date '+%b %d %H:%M') My server disks" \
    --license-type "AWS" \
    --disk-containers '[
    {
      "Description": "First disk",
      "Format": "vmdk",
      "UserBucket": {
        "S3Bucket": "amzn-s3-demo-import-bucket",
        "S3Key": "disks/my-server-vm-disk2.vmdk"
      }
    },
    {
      "Description": "Second disk",
      "Format": "vmdk",
      "UserBucket": {
        "S3Bucket": "amzn-s3-demo-import-bucket",
        "S3Key": "disks/my-server-vm-disk2.vmdk"
      }
    }
  ]'
```

------
#### [ PowerShell ]

Use the [Import-EC2Image](https://docs.aws.amazon.com/powershell/latest/reference/items/Import-EC2Image.html) cmdlet as follows.

```
Import-EC2Image `
    -Description ((Get-Date -Format "MMM dd HH:mm ") + "My server disks") `
    -LicenseType "AWS" `
    -DiskContainer @(
        @{
            Description = "First disk"
            Format = "vmdk"
            UserBucket = @{
                S3Bucket = "amzn-s3-demo-import-bucket"
                S3Key = "disks/my-server-vm-disk1.vmdk"
            }
        },
        @{
            Description = "Second disk"
            Format = "vmdk"
            UserBucket = @{
                S3Bucket = "amzn-s3-demo-import-bucket"
                S3Key = "disks/my-server-vm-disk2.vmdk"
            }
        }
    )
```

------

### Example 3: Import with the encrypted option enabled
<a name="import-vm-encrypted"></a>

The CMK provided for encryption must not be disabled during the entire import process. For more information, see [Amazon EBS encryption](https://docs.aws.amazon.com/ebs/latest/userguide/ebs-encryption.html) in the *Amazon EBS User Guide*.

------
#### [ AWS CLI ]

Use the following [https://docs.aws.amazon.com/cli/latest/reference/ec2/import-image.html](https://docs.aws.amazon.com/cli/latest/reference/ec2/import-image.html) command.

```
aws ec2 import-image \
    --description "$(date '+%b %d %H:%M') My server OVA" \
    --encrypted \
    --kms-key-id 0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE \
    --disk-containers '[{
        "Format": "OVA",
        "UserBucket": {
          "S3Bucket": "amzn-s3-demo-import-bucket",
          "S3Key": "vms/my-server-vm.ova"
        }
    }]'
```

------
#### [ PowerShell ]

Use the [Import-EC2Image](https://docs.aws.amazon.com/powershell/latest/reference/items/Import-EC2Image.html) cmdlet as follows.

```
Import-EC2Image `
    -Description ((Get-Date -Format "MMM dd HH:mm ") + "My server disks") `
    -LicenseType "AWS" `
    -DiskContainer @(
        @{
            Format = "OVA"
            UserBucket = @{
                S3Bucket = "amzn-s3-demo-import-bucket"
                S3Key = "vms/my-server-vm.ova"
            }0
        }
    ) `
    -Encrypted $true `
    -KmsKeyId "alias/aws/ebs"
```

------

### Example 4: Import an image using Migration Hub Orchestrator
<a name="import-vm-mho"></a>

------
#### [ Console ]

**To import an image using a template**

1. Open the [Migration Hub Orchestrator console](https://console.aws.amazon.com/migrationhub/orchestrator).

1. In the navigation pane, choose **Create migration workflow**.

1. On the **Choose a workflow template** page, choose the **Import virtual images to AWS** template.

1. Configure and submit your workflow to begin the VM import. For more information, see the [https://docs.aws.amazon.com/migrationhub-orchestrator/latest/userguide/import-vm-images.html](https://docs.aws.amazon.com/migrationhub-orchestrator/latest/userguide/import-vm-images.html).

------

# Monitor an import image task
<a name="check-import-task-status"></a>

You can monitor the progress of an import image task for VM Import/Export. The following are the status values for an import image task:
+ `active` — The import task is in progress.
+ `deleting` — The import task is being canceled.
+ `deleted` — The import task is canceled.
+ `updating` — Import status is updating.
+ `validating` — The imported image is being validated.
+ `validated` — The imported image was validated.
+ `converting` — The imported image is being converted into an AMI.
+ `completed` — The import task is completed and the AMI is ready to use.

------
#### [ AWS CLI ]

**To get the status of an import image task**  
Use the following [describe-import-image-tasks](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-import-image-tasks.html) command.

```
aws ec2 describe-import-image-tasks \
    --import-task-ids import-ami-1234567890abcdef0
```

The following is example output. When the import task is completed, the ID of the AMI is provided in `ImageId`.

```
{
    "ImportImageTasks": [
        {
            "ImportTaskId": "import-ami-01234567890abcdef",
            "ImageId": "ami-1234567890EXAMPLE",
            "SnapshotDetails": [
                {
                    "DiskImageSize": 705638400.0,
                    "Format": "ova",
                    "SnapshotId": "snap-111222333444aaabb",
                    "Status": "completed",
                    "UserBucket": {
                        "S3Bucket": "amzn-s3-demo-import-bucket",
                        "S3Key": "vms/my-server-vm.ova"
                    }
                }
            ],
            "Status": "completed"
        }
    ]
}
```

**To get the status of all import image tasks**  
Use the following [describe-import-image-tasks](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-import-image-tasks.html) command. The **sed** command truncates the status message. If the task fails and the status message is long, it makes the table harder to read.

```
aws ec2 describe-import-image-tasks \
  --query "ImportImageTasks[*].{Description:Description, Progress:Progress, Status:Status, ImportTaskId:ImportTaskId, StatusMessage:StatusMessage}" \
  --output table | \
    sed 's/\(.\{120\}\).*/\1|/'
```

The following is example output. You can display any additional fields that you need.

```
+---------------------+-------------------------------+-----------+----------+-----------------
|    Description      |         ImportTaskId          | Progress  | Status   |  StatusMessage |
+----------------------------------+------------------+-----------+----------+----------------+
|  My server disks    |  import-ami-01234567890abaaaa |  62       |  active  |  booting       |
|  My server OVA      |  import-ami-01234567890abbbbb |  62       |  active  |  booting       |
|  My server disks    |  import-ami-01234567890accccc |  62       |  active  |  booting       |
+----------------------------------+------------------+-----------+----------+----------------+
```

------
#### [ PowerShell ]

**To get the status of an import image task**  
Use the [Get-EC2ImportImageTask](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ImportImageTask.html) cmdlet as follows.

```
Get-EC2ImportImageTask `
    -ImportTaskId import-ami-01234567890abcdef |
        Format-List ImportTaskId, Status, Progress, ImageId, 
           @{Name='SnapshotDetails';Expression={ $_.SnapshotDetails | Out-String }}, 
           @{Name='UserBucket';Expression={ $_.SnapshotDetails.UserBucket | Out-String }},
```

The following is example output. When the import task is completed, the ID of the AMI is provided in `ImageId`.

```
ImportTaskId          : import-ami-01234567890abcdef
Status                : completed
Progress              : 
ImageId               : ami-1234567890EXAMPLE
SnapshotDetails       : 
                        Description   : 
                        DeviceName    : /dev/sda1
                        DiskImageSize : 549272064
                        Format        : VMDK
                        Progress      : 
                        SnapshotId    : snap-111222333444aaabb
                        Status        : completed
                        StatusMessage : 
                        Url           : 
                        UserBucket    : Amazon.EC2.Model.UserBucketDetails
UserBucket            : 
                        S3Bucket : amzn-s3-demo-import-bucket
                        S3Key    : vms/my-server-vm.ova
```

**To get the status of all import image tasks**  
Use the [Get-EC2ImportImageTask](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ImportImageTask.html) cmdlet as follows.

```
Get-EC2ImportImageTask | 
    Format-Table Description, ImportTaskId, Progress, Status, StatusMessage -AutoSize
```

The following is example output. You can display any additional fields that you need.

```
Description       ImportTaskId                 Progress Status     StatusMessage
----------------- ------------                 -------- ------     -------------
My server disks   import-ami-01234567890abaaaa 62       active     booting
My server OVA     import-ami-01234567890abbbbb 62       active     booting
My server disks   import-ami-01234567890accccc          completed
```

------

# Cancel an import image task
<a name="cancel-upload"></a>

After you start an image import task using VM Import/Export, you can cancel the import operation if needed.

To describe your import image tasks, see [Monitor an import image task](check-import-task-status.md).

------
#### [ AWS CLI ]

**To cancel an import image task**  
Use the [cancel-import-task](https://docs.aws.amazon.com/cli/latest/reference/ec2/cancel-import-task.html) command.

```
aws ec2 cancel-import-task \
    --import-task-id import-ami-1234567890abcdef0
```

------
#### [ PowerShell ]

**To cancel an import image task**  
Use the [Stop-EC2ImportTask](https://docs.aws.amazon.com/powershell/latest/reference/items/Stop-EC2ImportTask.html) cmdlet.

```
Stop-EC2ImportTask `
    -ImportTaskId import-ami-1234567890abcdef0
```

------

# Create an EC2 instance from an imported image
<a name="import-vm-next-steps"></a>

After the import image task is complete, you can launch an instance using the resulting AMI or copy the AMI to another Region. For more information, see the following documentation in the *Amazon EC2 User Guide*:
+ [Launch an instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-instance-wizard.html)
+ [Copy an AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/CopyingAMIs.html)

For some operating systems, the device drivers for enhanced networking and NVMe block devices that are required by [instances built on the Nitro system](https://docs.aws.amazon.com/ec2/latest/instancetypes/ec2-nitro-instances.html) are not installed automatically during import. To install these drivers manually, use the directions in the following documentation in the *Amazon EC2 User Guide*.
+ (Windows instances) Install the latest version of one of the following: [EC2LaunchV2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2launch-v2-install.html), [EC2Launch](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2launch-download.html), or [EC2Config](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UsingConfig_Install.html).
+ (Windows instances) [Install or upgrade AWS NVMe drivers using PowerShell](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/aws-nvme-drivers.html#install-nvme-drivers)
+ (Linux instances) [Install or upgrade the NVMe driver](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#install-nvme-driver)
+ [Enable enhanced networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking-ena.html)

After you finish customizing your instance, create you can create a new image from the customized instance. For more information, see [Create an AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-ami.html) in the *Amazon EC2 User Guide*.