How do I use VM Import/Export to export a VM-based instance on my AMI?

4 minute read
0

I want to export a copy of my Amazon Machine Image (AMI) as a virtual machine (VM) to deploy in my on-site virtualization environment.

Short description

Use the AWS Command Line Interface (AWS CLI) and VM Import/Export to start an image export task. This task exports a copy of your AMI as a VM file that's written to an Amazon Simple Storage Service (Amazon S3) bucket. Use the exported VM to deploy a new and standardized instance in your on-site virtualization environment. Most AMIs can export to Citrix Xen, Microsoft Hyper-V, or VMware vSphere.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Prerequisites:

Export a copy of your AMI as an image

Note: You can't export an instance that was created from a Windows AMI provided by AWS or a Windows Marketplace AMI. You can export only Windows instances that are originally imported as Bring your own license (BYOL) through VM Import/Export, AWS Application Migration Service (MGN), or AWS Elastic Disaster Recovery (AWS DRS).

To run the image export task, complete the following steps:

  1. Create an Amazon Elastic Block Store (Amazon EBS) backed AMI from the Amazon Elastic Compute Cloud (Amazon EC2) instance that you want to export.

  2. Install the AWS CLI on a client machine. Then, configure the AWS CLI with the AWS credentials for your IAM user.

  3. Create a new Amazon S3 bucket in the same AWS Region as the AMI that you want to export.

  4. Activate AWS Security Token Service (AWS STS) in the Region that you want to use for VM Import/Export. Then, create the required service role.

  5. From the client machine that you installed the AWS CLI on, run the export-image command to start the export image task:

    aws ec2 export-image --image-id `ami-1234567890abcdef0` --disk-image-format example-disk-image-format --s3-export-location S3Bucket=example-export-bucket,S3Prefix=exports/

    Note: Replace ami-1234567890abcdef0 with your AMI id. Replace example-disk-image-format with your desired format. Replace example-export-bucket with the name of your Amazon S3 bucket.

    Example output:

    {   
        "DiskImageFormat": "vmdk",
        "ExportImageTaskId": "export-ami-1234567890abcdef0",
        "ImageId": "example-ami-id",
        "RoleName": "vmimport",
        "Progress": "0",
        "S3ExportLocation": {
            "S3Bucket": "example-export-bucket",
            "S3Prefix": "exports/"
        },
        "Status": "active",
        "StatusMessage": "validating"
    }

    In the preceding example, the Amazon S3 key prefixexport-ami-id.format writes the exported file to your specified Amazon S3 bucket. You can add prefixes to the exported file.

  6. To check the status of your export image task, run the describe-export-image-tasks command:

    aws ec2 describe-export-image-tasks --export-image-task-ids export-example-ami-id

    Note: Replace export-example-ami-id with your export task id.

    Example output:

    {    "ExportImageTasks": [
            {
                "ExportImageTaskId": "export-ami-1234567890abcdef0",
                "Progress": "21",
                "S3ExportLocation": {
                    "S3Bucket": "my-export-bucket",
                    "S3Prefix": "exports/"
                },
                "Status": "active",
                "StatusMessage": "updating"
            }
        ]
    }
  7. Confirm that the status of your export image task changes to completed. If the status is completed, then your exported file is ready as an object in your Amazon S3 bucket.
    Example output of completed status:

    {    "ExportImageTasks": [
            {
                "ExportImageTaskId": "example-export-ami-id",
                "S3ExportLocation": {
                    "S3Bucket": "example-export-bucket",
                    "S3Prefix": "exports/"
                },
                "Status": "completed"
            }
        ]
    }
  8. Use the Amazon S3 console to access your Amazon S3 bucket. Then, download the object.

Related information

Exporting a VM directly from an Amazon Machine Image (AMI) using VM Import/Export

Create an IAM user in your AWS account

AWS security credentials

Amazon Machine Images in Amazon EC2

Troubleshooting VM Import/Export

AWS OFFICIAL
AWS OFFICIALUpdated a month ago
2 Comments

The step 6 is not aws ec2 describe-export-image-tasks --example-image-task-id example-ami-id. Instead it is aws ec2 describe-export-image-tasks --export-image-task-id export-example-ami-id

replied a year ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied a year ago