

# Export an EC2 instance as a VM using VM Import/Export
<a name="vmexport"></a>

Exporting as a VM is useful when you want to deploy a copy of an Amazon EC2 instance in your virtualization environment. You can export most EC2 instances to Citrix Xen, Microsoft Hyper-V, or VMware vSphere.

When you export an instance, 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 instance from Amazon EC2
](vmexport-prerequisites.md)
+ [

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

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

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

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

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

To export a VM from Amazon EC2, first meet the following prerequisites:
+ Create an Amazon S3 bucket for storing the exported instances or choose an existing bucket. The bucket must be in the Region where you want export your VMs. Additionally, the bucket must belong to the AWS account where you are performing the export operation. For more information, see the [Amazon Simple Storage Service User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/).
+ You can't export a VM to an S3 bucket that uses the bucket owner enforced setting for S3 Object Ownership because ACLs are disabled. For more information, see [Configuring ACLs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/managing-acls.html) in the *Amazon Simple Storage Service User Guide*.
+ Prepare your S3 bucket by attaching an access control list (ACL) containing the following grants. For more information, see [Managing access with ACLs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/acls.html) in the *Amazon Simple Storage Service User Guide*.
  + For each `Grantee`, provide the following permissions:
    + `READ_ACP` (In the Amazon S3 console, **Bucket ACL** should have the **Read** permission)
    + `WRITE` (In the Amazon S3 console, **Objects** should have the **Write** permission)
  + For `Grantee`, provide the appropriate Region-specific canonical account ID:
    + **Africa (Cape Town)** – 3f7744aeebaf91dd60ab135eb1cf908700c8d2bc9133e61261e6c582be6e33ee
    + **Asia Pacific (Hong Kong)** – 97ee7ab57cc9b5034f31e107741a968e595c0d7a19ec23330eae8d045a46edfb
    + **Asia Pacific (Hyderabad)** – 77ab5ec9eac9ade710b7defed37fe0640f93c5eb76ea65a64da49930965f18ca
    + **Asia Pacific (Jakarta)** – de34aaa6b2875fa3d5086459cb4e03147cf1a9f7d03d82f02bedb991ff3d1df5
    + **Asia Pacific (Malaysia)** – ed006f67543afcfe0779e356e52d5ed53fa45f95bcd7d277147dfc027aaca0e7
    + **Asia Pacific (Melbourne)** – 8b8ea36ab97c280aa8558c57a380353ac7712f01f82c21598afbb17e188b9ad5
    + **Asia Pacific (New Zealand)** – 2dc8fa4ca1c59da5c6a4c5b0e397eea130ec62e49f18cff179034665fd20e8a2
    + **Asia Pacific (Osaka)** – 40f22ffd22d6db3b71544ed6cd00c8952d8b0a63a87d58d5b074ec60397db8c9
    + **Asia Pacific (Taipei)** – a9fa0eb7c8483f9558cd14b24d16e9c4d1555261a320b586a3a06908ff0047ce
    + **Asia Pacific (Thailand)** – d011fe83abcc227a7ac0f914ce411d3630c4ef735e92e88ce0aa796dcfecfbdd
    + **Canada West (Calgary)** – 78e12f8d798f89502177975c4ccdac686c583765cea2bf06e9b34224e2953c83
    + **Europe (Milan)** – 04636d9a349e458b0c1cbf1421858b9788b4ec28b066148d4907bb15c52b5b9c
    + **Europe (Spain)** – 6e81c4c52a37a7f59e103625162ed97bcd0e646593adb107d21310d093151518
    + **Europe (Zurich)** – 5d9fcea77b2fb3df05fc15c893f212ae1d02adb4b24c13e18586db728a48da67
    + **Israel (Tel Aviv)** – 328a78de7561501444823ebeb59152eca7cb58fee2fe2e4223c2cdd9f93ae931
    + **Mexico (Central)** – edaff67fe25d544b855bd0ba9a74a99a2584ab89ceda0a9661bdbeca530d0fca
    + **Middle East (Bahrain)** – aa763f2cf70006650562c62a09433f04353db3cba6ba6aeb3550fdc8065d3d9f
    + **Middle East (UAE)** – 7d3018832562b7b6c126f5832211fae90bd3eee3ed3afde192d990690267e475
    + **AWS GovCloud (US)** – af913ca13efe7a94b88392711f6cfc8aa07c9d1454d4f190a624b126733a5602
    + **All other Regions** – c4d8eabf8db69dbe46bfe0e517100c554f01200b104d59cd408e777ba442a322

## Configure your S3 bucket
<a name="vmexport-configure-bucket"></a>

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

**To configure the S3 bucket**

1. Open the Amazon S3 console at [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).

1. Select the bucket in which to store the exported instances.

1. On the **Permissions** tab, change the object ownership to **Bucket owner preferred**.

1. Attach the following bucket policy. For `CanonicalUser`, enter the canonical account ID for the bucket Region. For `Resource`, enter the name of your bucket in the bucket ARNs.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "GrantReadAclAndWrite",
               "Effect": "Allow",
               "Principal": {
                   "CanonicalUser": "c4d8eabf8db69dbe46bfe0e517100c554f01200b104d59cd408e777ba442a322"
               },
               "Action": [
                   "s3:GetBucketAcl",
                   "s3:PutObject"
               ],
               "Resource": [
                   "arn:aws:s3:::amzn-s3-demo-export-bucket",
                   "arn:aws:s3:::amzn-s3-demo-export-bucket/*"
               ]
           }
       ]
   }
   ```

------

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

**To configure the S3 bucket**  
Use the [put-bucket-ownership-controls](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-ownership-controls.html) command to change the object ownership.

```
aws s3api put-bucket-ownership-controls \
    --bucket amzn-s3-demo-export-bucket \
    --ownership-controls='{"Rules":[{"ObjectOwnership":"BucketOwnerPreferred"}]}'
```

Use the [put-bucket-policy](https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-policy.html) command to attach the bucket policy. For `CanonicalUser`, enter the canonical account ID for the bucket Region. For `Resource`, enter the name of your bucket in the bucket ARNs.

```
aws s3api put-bucket-policy \
    --bucket amzn-s3-demo-export-bucket \
    --policy \
'{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GrantReadAcpAndWrite",
            "Effect": "Allow",
            "Principal": {
                "CanonicalUser": "c4d8eabf8db69dbe46bfe0e517100c554f01200b104d59cd408e777ba442a322"
            },
            "Action": [
                "s3:GetBucketAcl",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-export-bucket",
                "arn:aws:s3:::amzn-s3-demo-export-bucket/*"
            ]
        }
    ]
}'
```

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

**To configure the S3 bucket**  
Use the [Write-S3BucketOwnershipControl](https://docs.aws.amazon.com/powershell/latest/reference/items/Write-S3BucketOwnershipControl.html) cmdlet to change the object ownership.

```
Write-S3BucketOwnershipControl `
    -BucketName "amzn-s3-demo-export-bucket" `
    -OwnershipControls_Rule @{ObjectOwnership="BucketOwnerPreferred"}
```

Use the [Write-S3BucketPolicy](https://docs.aws.amazon.com/powershell/latest/reference/items/Write-S3BucketPolicy.html) cmdlet to attach the bucket policy. For `CanonicalUser`, enter the canonical account ID for the bucket Region. For `Resource`, enter the name of your bucket in the bucket ARNs.

```
Write-S3BucketPolicy `
    -BucketName "amzn-s3-demo-export-bucket" `
    -Policy `
'{
    "Version": "2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GrantReadAcpAndWrite",
            "Effect": "Allow",
            "Principal": {
                "CanonicalUser": "c4d8eabf8db69dbe46bfe0e517100c554f01200b104d59cd408e777ba442a322"
            },
            "Action": [
                "s3:GetBucketAcl",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::amzn-s3-demo-export-bucket",
                "arn:aws:s3:::amzn-s3-demo-export-bucket/*"
            ]
        }
    ]
}'
```

------

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

Exporting instances and volumes is subject to the following limitations:
+ You must export your instances and volumes to one of the following image formats that your virtualization environment supports:
  + Open Virtual Appliance (OVA), which is compatible with VMware vSphere versions 4, 5, and 6.
  + 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.
+ You can't export an instance if it contains third-party software provided by AWS. For example, VM Export cannot export Windows or SQL Server instances, or any instance created from an image in the AWS Marketplace.
+ You can't export an instance with encrypted EBS snapshots in the block device mapping.
+ You can't export an instance with instance store volumes in the block device mapping.
+ You can only export EBS volumes that are specified in the block device mapping, not EBS volumes attached after instance launch.
+ You can't export an instance launched from an imported image if you deleted the AMI or the EBS snapshot for the AMI. To work around the issue, create an AMI from the instance and export the AMI.
+ You can't export an instance that has more than one virtual disk.
+ You can't export an instance that has more than one network interface.
+ You can't export an instance from Amazon EC2 if you've shared it from another AWS account.
+ 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. You cannot export to an S3 bucket encrypted using SSE-KMS.
+ 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.

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

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

```
prefixexport-i-xxxxxxxxxxxxxxxxx.format
```

For example, if the bucket name is `amzn-s3-demo-export-bucket`, the prefix is `vms/`, and the format is OVA, the exported file is written to `amzn-s3-demo-export-bucket/vms/export-i-1234567890abcdef0.ova`.

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

**Important**  
Your instance might reboot during the export process. Ensure that you are performing this action when some downtime is acceptable.

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

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

```
aws ec2 create-instance-export-task \
    --description "$(date '+%b %d %H:%M') My instance export" \
    --instance-id i-1234567890abcdef0 \
    --target-environment vmware \
    --export-to-s3-task '{
        "ContainerFormat": "ova",
        "DiskImageFormat": "VMDK",
        "S3Bucket": "amzn-s3-demo-export-bucket",
        "S3Prefix": "vms/"
    }'
```

The following is an example response. The status shown is `active`, which means that the export task is in progress. The instance export is finished when the status is `completed`.

```
{
    "ExportTask": {
        "Description": "Jul 15 14:55 My instance export",
        "ExportTaskId": "export-i-021345abcdef6789",
        "ExportToS3Task": {
            "ContainerFormat": "ova",
            "DiskImageFormat": "vmdk",
            "S3Bucket": "amzn-s3-demo-export-bucket",
            "S3Key": "vms/export-i-021345abcdef6789.ova"
        },
        "InstanceExportDetails": {
            "InstanceId": "i-1234567890abcdef0",
            "TargetEnvironment": "vmware"
        },
        "State": "active"
    }
}
```

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

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

```
New-EC2InstanceExportTask `
    -Description ((Get-Date -Format "MMM dd HH:mm ") + "My instance export") `
    -InstanceId "i-1234567890abcdef0" `
    -TargetEnvironment "vmware" `
    -ExportToS3Task_ContainerFormat "ova" `
    -ExportToS3Task_DiskImageFormat "VMDK" `
    -ExportToS3Task_S3Bucket "amzn-s3-demo-export-bucket" `
    -ExportToS3Task_S3Prefix "vms/"
```

The following is an example response. The status shown is `active`, which means that the export task is in progress. The instance export is finished when the status is `completed`.

```
Description           : Jul 15 14:53 My instance export
ExportTaskId          : export-i-021345abcdef6789
ExportToS3Task        : Amazon.EC2.Model.ExportToS3Task
InstanceExportDetails : Amazon.EC2.Model.InstanceExportDetails
State                 : active
StatusMessage         : 
Tags                  : {}
```

------

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

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

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

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

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

The following is example output. The status shown is `active`. The VM is ready to use when the status is `completed`.

```
{
    "ExportTasks": [
        {
            "ExportTaskId": "export-i-1234567890abcdef0",
            "ExportToS3Task": {
                "ContainerFormat": "ova",
                "DiskImageFormat": "VMDK",
                "S3Bucket": "amzn-s3-demo-export-bucket",
                "S3Key": "vms/export-i-1234567890abcdef0.ova"
            },
            "InstanceExportDetails": {
                "InstanceId": "i-1234567890abcdef0",
                "TargetEnvironment": "vmware"
            },
            "State": "active"
        }
    ]
}
```

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

```
aws ec2 describe-export-tasks \
    --query "ExportTasks[*].{Description:Description,ExportTaskId:ExportTaskId,State:State,S3Bucket:ExportToS3Task.S3Bucket,InstanceId:InstanceExportDetails.InstanceId}" \
    --output table
```

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

```
------------------------------------------------------------------------------------------------------------------------------------
|                                                    DescribeExportTasks                                                           |
+----------------------------------+-----------------------------+----------------------+-----------------------------+------------+
|            Description           |        ExportTaskId         |      InstanceId      |     S3Bucket                |    State   |
+----------------------------------+-----------------------------+----------------------+-----------------------------+------------+
|  Jul 15 01:18 My instance export |  export-i-01234567890abaaaa |  None                |  amzn-s3-demo-export-bucket |  active    |
|  Jul 15 11:01 My instance export |  export-i-01234567890abbbbb |  None                |  amzn-s3-demo-export-bucket |  active    |
|  Jul 13 11:00 My instance export |  export-i-01234567890accccc |  i-0abcdef1234567890 |  amzn-s3-demo-export-bucket |  completed |
+----------------------------------+-----------------------------+----------------------+-----------------------------+------------+
```

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

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

```
Get-EC2ExportTask `
    -ExportTaskId export-i-1234567890abcdef0 |
        Format-List *, 
           @{Name='ExportToS3Task';Expression={$_.ExportToS3Task | Out-string}},
           @{Name='InstanceExportDetails';Expression={$_.InstanceExportDetails | Out-string}}
```

The following is example output. The status shown is `active`. The VM is ready to use when the status is `completed`.

```
Description           : Jul 15 14:55 My instance export
ExportTaskId          : export-i-1234567890abcdef0
ExportToS3Task        : Amazon.EC2.Model.ExportToS3Task
InstanceExportDetails : Amazon.EC2.Model.InstanceExportDetails
State                 : completed
StatusMessage         : 
Tags                  : {}
ExportToS3Task        : 
                        ContainerFormat : ova
                        DiskImageFormat : VMDK
                        S3Bucket        : amzn-s3-demo-export-bucket
                        S3Key           : vms/export-i-1234567890abcdef0.ova
InstanceExportDetails : 
                        InstanceId        : i-1234567890abcdef0  
                        TargetEnvironment : vmware
```

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

```
Get-EC2ExportTask |
    Format-Table Description, ExportTaskId, State,
        @{Name='S3Bucket';Expression={$_.ExportToS3Task.S3Bucket}},
        @{Name='InstanceId';Expression={$_.InstanceExportDetails.InstanceId}}
```

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

```
Description                     ExportTaskId               State     S3Bucket                     InstanceId
-----------                     ------------               -----     --------                     ----------
Jul 15 01:18 My instance export export-i-01234567890abaaaa active    amzn-s3-demo-export-bucket   
Jul 15 11:01 My instance export export-i-01234567890abbbbb active    amzn-s3-demo-export-bucket   
Jul 13 11:00 My instance export export-i-01234567890accccc completed amzn-s3-demo-export-bucket   i-0abcdef1234567890
```

------

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

After you start an instance export task using VM Import/Export, you can cancel the export operation if needed. The cancel operation removes all artifacts of the export, including any partially created Amazon S3 objects. If the export task is complete or is in the process of transferring the final disk image, the cancel operation fails and returns an error.

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

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

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

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

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

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

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

------