View a markdown version of this page

Use CreateInstanceExportTask with a CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use CreateInstanceExportTask with a CLI

The following code examples show how to use CreateInstanceExportTask.

CLI
AWS CLI

To export an instance

The following create-instance-export-task example creates a task to export the instance i-1234567890abcdef0 to the Amazon S3 bucket myexportbucket.

aws ec2 create-instance-export-task \ --description "RHEL5 instance" \ --instance-id i-1234567890abcdef0 \ --target-environment vmware \ --export-to-s3-task DiskImageFormat=vmdk,ContainerFormat=ova,S3Bucket=myexportbucket,S3Prefix=RHEL5

Output:

{ "ExportTask": { "State": "active", "InstanceExportDetails": { "InstanceId": "i-1234567890abcdef0", "TargetEnvironment": "vmware" }, "ExportToS3Task": { "S3Bucket": "myexportbucket", "S3Key": "RHEL5export-i-fh8sjjsq.ova", "DiskImageFormat": "vmdk", "ContainerFormat": "ova" }, "Description": "RHEL5 instance", "ExportTaskId": "export-i-fh8sjjsq" } }

For more information, see Export an EC2 instance as a VM using VM Import/Export in the VM Import/Export User Guide.

PowerShell
Tools for PowerShell V4

Example 1: This example exports a stopped instance, i-0800b00a00EXAMPLE, as a virtual hard disk (VHD) to the S3 bucket testbucket-export-instances-2019. The target environment is Microsoft, and the region parameter is added because the instance is in the us-east-1 region, while the user's default AWS Region is not us-east-1. To get the status of the export task, copy the ExportTaskId value from the results of this command, then run Get-EC2ExportTask -ExportTaskId export_task_ID_from_results.

New-EC2InstanceExportTask -InstanceId i-0800b00a00EXAMPLE -ExportToS3Task_DiskImageFormat VHD -ExportToS3Task_S3Bucket "amzn-s3-demo-bucket" -TargetEnvironment Microsoft -Region us-east-1

Output:

Description : ExportTaskId : export-i-077c73108aEXAMPLE ExportToS3Task : Amazon.EC2.Model.ExportToS3Task InstanceExportDetails : Amazon.EC2.Model.InstanceExportDetails State : active StatusMessage :
Tools for PowerShell V5

Example 1: This example exports a stopped instance, i-0800b00a00EXAMPLE, as a virtual hard disk (VHD) to the S3 bucket testbucket-export-instances-2019. The target environment is Microsoft, and the region parameter is added because the instance is in the us-east-1 region, while the user's default AWS Region is not us-east-1. To get the status of the export task, copy the ExportTaskId value from the results of this command, then run Get-EC2ExportTask -ExportTaskId export_task_ID_from_results.

New-EC2InstanceExportTask -InstanceId i-0800b00a00EXAMPLE -ExportToS3Task_DiskImageFormat VHD -ExportToS3Task_S3Bucket "amzn-s3-demo-bucket" -TargetEnvironment Microsoft -Region us-east-1

Output:

Description : ExportTaskId : export-i-077c73108aEXAMPLE ExportToS3Task : Amazon.EC2.Model.ExportToS3Task InstanceExportDetails : Amazon.EC2.Model.InstanceExportDetails State : active StatusMessage :