

# Export a VM from an Amazon Machine Image (AMI) using VM Import/Export
<a name="vmexport_image"></a>

Exporting a VM file based on an Amazon Machine Image (AMI) is useful when you want to deploy a new, standardized instance in your virtualization environment. You can export most AMIs to Citrix Xen, Microsoft Hyper-V, or VMware vSphere.

When you export an image, you are charged the standard Amazon S3 rates for the bucket where the exported VM is stored. In addition, there might be a small charge for the temporary use of an Amazon EBS snapshot. For more information about Amazon S3 pricing, see [Amazon Simple Storage Service Pricing](https://aws.amazon.com/s3/pricing/).

**Topics**
+ [

# Prerequisites for exporting an image from Amazon EC2
](prerequisites-image-export.md)
+ [

# Considerations for image export
](limits-image-export.md)
+ [

# Start an export image task
](start-image-export.md)
+ [

# Monitor an export image task
](monitor-image-export.md)
+ [

# Cancel an export image task
](cancel-image-export.md)

# Prerequisites for exporting an image from Amazon EC2
<a name="prerequisites-image-export"></a>

To export a VM from Amazon EC2, first meet the following prerequisites.
+ Install the AWS CLI. For more information, 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.
+ 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 export your VMs. Additionally, the bucket must belong to the AWS account where you are performing the export operation. 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).

# Considerations for image export
<a name="limits-image-export"></a>

Exporting images and volumes is subject to the following limitations:
+ You must export to one of the following image formats that your virtualization environment supports:
  + Virtual Hard Disk (VHD), which is compatible with Citrix Xen and Microsoft Hyper-V virtualization products.
  + Stream-optimized ESX Virtual Machine Disk (VMDK), which is compatible with VMware ESX and VMware vSphere versions 4, 5, and 6.
  + Raw format.
+ The base AMI used to launch an instance must exist when you attempt to export the instance. If you have deleted the AMI, the export fails.
+ VM Import/Export only supports exporting VMs to an S3 bucket in the same AWS account that you export them from.
+ Export operations do not support hybrid configurations. GRUB2 must be enabled for either BIOS or UEFI, but it can't be enabled for both.
+ You can't export an image if it contains third-party software provided by AWS. For example, VM Export cannot export Windows or SQL Server images, or any image created from an image in the AWS Marketplace.
+ You can't export an image with encrypted EBS snapshots in the block device mapping.
+ You can only export EBS data volumes that are specified in the block device mapping, not EBS volumes attached after instance launch.
+ You can't export an image from Amazon EC2 if you've shared it from another AWS account.
+ You can't have multiple export image tasks in progress for the same AMI at the same time.
+ By default, you can't have more than 5 conversion tasks per Region in progress at the same time. This limit is adjustable up to 20.
+ VMs with volumes larger than 1 TiB are not supported.
+ You can export a volume to either an unencrypted S3 bucket or to a bucket encrypted using SSE-S3 encryption. You cannot export to an S3 bucket encrypted using SSE-KMS encryption.

# Start an export image task
<a name="start-image-export"></a>

When you export your image using VM Import/Export, the exported file is written to the specified S3 bucket using the following S3 key:

```
prefixexport-ami-xxxxxxxxxxxxxxxxx.format
```

For example, if the bucket name is `amzn-s3-demo-export-bucket`, the prefix is `exports/`, and the format is VMDK, the exported image is written to `amzn-s3-demo-export-bucket/exports/export-ami-1234567890abcdef0.vmdk`.

For information about the supported formats, see [Considerations for image export](limits-image-export.md).

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

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

```
aws ec2 export-image \
    --description "$(date '+%b %d %H:%M') My image export" \
    --image-id ami-1234567890abcdef0 \
    --disk-image-format VMDK \
    --s3-export-location S3Bucket=amzn-s3-demo-export-bucket,S3Prefix=exports/
```

The following is example output.

```
{
    "Description": "Jul 15 16:31 My image export",
    "DiskImageFormat": "VMDK",
    "ExportImageTaskId": "export-ami-36a041c1000000000",
    "ImageId": "ami-1234567890abcdef0",
    "Progress": "0",
    "S3ExportLocation": {
        "S3Bucket": "amzn-s3-demo-export-bucket",
        "S3Prefix": "exports/"
    },
    "Status": "active",
    "StatusMessage": "validating"
}
```

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

**To export an image**  
Use the [Export-EC2Image](https://docs.aws.amazon.com/powershell/latest/reference/items/Export-EC2Image.html) cmdlet.

```
Export-EC2Image `
    -Description ((Get-Date -Format "MMM dd HH:mm ") + "My image export") `
    -ImageId ami-1234567890abcdef0 `
    -DiskImageFormat VMDK `
    -S3ExportLocation_S3Bucket amzn-s3-demo-export-bucket `
    -S3ExportLocation_S3Prefix exports/
```

The following is example output.

```
Description       : Jul 15 16:35 My image export
DiskImageFormat   : VMDK
ExportImageTaskId : export-ami-36a041c1000000000
ImageId           : ami-1234567890abcdef0
Progress          : 0
RoleName          : 
S3ExportLocation  : Amazon.EC2.Model.ExportTaskS3Location
Status            : active
StatusMessage     : validating
Tags              : {}
```

------

# Monitor an export image task
<a name="monitor-image-export"></a>

After you start an image export using VM Import/Export, you can monitor the export operation.

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

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

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

The following is example output. The status shown is `active`, which means that the export task is in progress. The image is ready to use when the status is `completed`.

```
{
  "ExportImageTasks": [
      {
          "Description": "Jul 15 16:31 My image export",
          "ExportImageTaskId": "export-ami-1234567890abcdef0",
          "Progress": "21",
          "S3ExportLocation": {
              "S3Bucket": "amzn-s3-demo-export-bucket",
              "S3Prefix": "exports/"
          },
          "Status": "active",
          "StatusMessage": "updating"
      }
  ]
}
```

**To monitor all export image tasks**  
Use the following [describe-export-image-tasks](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-export-image-tasks.html) command.

```
aws ec2 describe-export-image-tasks \
  --query "ExportImageTasks[*].{\
    Description:Description,\
    ExportImageTaskId:ExportImageTaskId,\
    ImageId:ImageId,\
    Status:Status,\
    Progress:Progress,\
    S3Bucket:S3ExportLocation.S3Bucket}" \
  --output table
```

The following is example output.

```
--------------------------------------------------------------------------------------------------------------------------------------------------
|                                                      DescribeExportImageTasks                                                                  |
+------------------------------+-------------------------------+------------------------+-----------+------------------------------+-------------+
|          Description         |       ExportImageTaskId       |        ImageId         | Progress  |          S3Bucket            |   Status    |
+------------------------------+-------------------------------+------------------------+-----------+------------------------------+-------------+
|  Jul 15 16:35 My image export|  export-ami-1234567890abcdef0 |                        |  80       |  amzn-s3-demo-export-bucket  |  active     |
|  Jul 15 16:31 My image export|  export-ami-1234567890abcdef1 |  ami-ab34567890abcdef0 |  None     |  amzn-s3-demo-export-bucket  |  completed  |
+------------------------------+-------------------------------+------------------------+-----------+------------------------------+-------------+
```

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

**To monitor an export image task**  
Use the [Get-EC2ExportImageTask](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ExportImageTask.html) cmdlet as follows.

```
Get-EC2ExportImageTask `
   -ExportImageTaskId export-ami-1234567890abcdef0 |
      Format-List *, 
         @{Name='S3ExportLocation';Expression={$_.S3ExportLocation | Format-List | Out-String}}
```

The following is example output. The status shown is `active`, which means that the export task is in progress. The image is ready to use when the status is `completed`.

```
Description       : Jul 15 16:35 My image export
ExportImageTaskId : export-ami-1234567890abcdef0
ImageId           : ami-ab34567890abcdeff
Progress          : 80
S3ExportLocation  : Amazon.EC2.Model.ExportTaskS3Location
Status            : active
StatusMessage     : converting
Tags              : {}
S3ExportLocation  : 
                    S3Bucket : amzn-s3-demo-export-bucket
                    S3Prefix : exports/
```

**To monitor all export image tasks**  
Use the [Get-EC2ExportImageTask](https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ExportImageTask.html) cmdlet as follows.

```
Get-EC2ExportImageTask | 
   Format-Table Description, ExportImageTaskId, ImageId, Status, Progress,  
   @{Name='S3Bucket';Expression={$_.S3ExportLocation.S3Bucket}}
```

The following is example output.

```
Description                  ExportImageTaskId            ImageId               Status    Progress S3Bucket
-----------                  -----------------            -------               ------    -------- --------
Jul 15 16:35 My image export export-ami-1234567890abcdef0                       active    80       amzn-s3-demo-export-bucket
Jul 15 16:31 My image export export-ami-1234567890abcdef1 ami-ab34567890abcdef0 completed          amzn-s3-demo-export-bucket
```

------

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

After you start an image export using VM Import/Export, you can cancel the export operation if needed. If you attempt to cancel the export task after it is complete or is in the process of transferring the final disk image, the cancel operation fails and returns an error.

To describe your export image tasks, see [Monitor an export image task](monitor-image-export.md).

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

**To cancel an export image task**  
Use the [cancel-export-task](https://docs.aws.amazon.com/cli/latest/reference/ec2/cancel-export-task.html) command. If the command succeeds, no output is returned.

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

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

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

```
Stop-EC2ExportTask `
    -ExportTaskId export-ami-1234567890abcdef0
```

------