Use ImportImage with an AWS SDK or CLI - Amazon Elastic Compute Cloud

Use ImportImage with an AWS SDK or CLI

The following code examples show how to use ImportImage.

CLI
AWS CLI

To import a VM image file as an AMI

The following import-image example imports the specified OVA.

<userinput>aws ec2 import-image \ --disk-containers Format=ova,UserBucket="{S3Bucket=my-import-bucket,S3Key=vms/my-server-vm.ova}"</userinput>

Output:

{ "ImportTaskId": "import-ami-1234567890abcdef0", "Progress": "2", "SnapshotDetails": [ { "DiskImageSize": 0.0, "Format": "ova", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.ova" } } ], "Status": "active", "StatusMessage": "pending" }
  • For API details, see ImportImage in AWS CLI Command Reference.

PowerShell
Tools for PowerShell

Example 1: This example imports a single-disk virtual machine image from the specified Amazon S3 bucket to Amazon EC2 with an idempotency token. The example requires that a VM Import Service Role with the default name 'vmimport' exists, with a policy allowing Amazon EC2 access to the specified bucket, as explained in the VM Import Prequisites topic. To use a custom role, specify the role name using the -RoleName parameter.

$container = New-Object Amazon.EC2.Model.ImageDiskContainer $container.Format="VMDK" $container.UserBucket = New-Object Amazon.EC2.Model.UserBucket $container.UserBucket.S3Bucket = "myVirtualMachineImages" $container.UserBucket.S3Key = "Win_2008_Server_Standard_SP2_64-bit-disk1.vmdk" $parms = @{ "ClientToken"="idempotencyToken" "Description"="Windows 2008 Standard Image Import" "Platform"="Windows" "LicenseType"="AWS" } Import-EC2Image -DiskContainer $container @parms

Output:

Architecture : Description : Windows 2008 Standard Image Hypervisor : ImageId : ImportTaskId : import-ami-abcdefgh LicenseType : AWS Platform : Windows Progress : 2 SnapshotDetails : {} Status : active StatusMessage : pending
  • For API details, see ImportImage in AWS Tools for PowerShell Cmdlet Reference.

For a complete list of AWS SDK developer guides and code examples, see Create Amazon EC2 resources using an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.