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

3 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 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

Prerequisites

Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Export a copy of your AMI as an image

To run the image export task, do the following actions:

  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.
    For Linux, see Create an Amazon EBS-backed Linux AMI.
    For Windows, see Create a custom Windows AMI.

  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 S3 bucket in the same AWS Region as the AMI that you plan to export.

  4. Activate AWS Security Token Service (AWS STS) in the Region that you 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 example-ami-id --disk-image-format example-disk-image-format --s3-export-location S3Bucket=example-export-bucket,S3Prefix=exports/

    Note: In this example, the Amazon S3 key prefixexport-ami-id.format writes the exported file to your specified S3 bucket. You can add prefixes to the exported file.
    Example export-image command 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"
    }
  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

    Example describe-export-image-tasks command 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. This indicates that your exported file is ready as an object in your 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 S3 bucket. Then, locate and download the object.

Related information

Exporting a VM directly from an Amazon Machine Image (AMI)

Creating an IAM user in your AWS account

AWS security credentials

Amazon Machine Images (AMI)

Troubleshooting VM Import/Export

AWS OFFICIAL
AWS OFFICIALUpdated 10 days 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

yush
replied 5 months ago

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

profile pictureAWS
MODERATOR
replied 5 months ago