DEV Community

Van Hoang Kha for AWS Community Builders

Posted on • Edited on

AWS Import/Export - Part 2: Export VM from AWS

Table of content:

  1. Configure S3 for exporting
  2. Export from instance
  3. Export from AMI
  4. Clean up resources

1. Configure S3 for exporting

When we export instances from AWS to virtualized environment formats, we will have to store them on the S3 bucket.

This process will be performed by the default AWS user vm-import-export@amazon.com. Therefore, you need to assign permissions to this user on the S3 bucket via the ACL.

Create an s3 bucket to store export.

  • Access the Amazon S3 Management console.
  • In the navigation bar, select Buckets.
  • Select Create bucket to create a new S3 bucket.
  • On the Create bucket page, set the parameters for the S3 bucket.
  • Bucket name: Enter the bucket name. This name must be unique and not duplicate. (Ex: import-bucket-2021)
  • Region: Select the storage region of the bucket.

Image description

Uncheck Block all public access to allow public access. AWS will then issue a warning, and you select I acknowledge that the current settings might result in this bucket and the objects within becoming public.

Image description

Select Create bucket.

Image description

Finish creating the bucket.

Image description

Edit Access control list(ACL). Select bucket owner enforced

Image description

Select ACLs enabled, select Save changes.

Image description

Select Add grantee

Image description

Enter Canonical ID and select Write Objects and Read of the Bucket ACL. Then select Save changes.

Image description

Canonical ID list of user vm-import-export@amazon.com by Region:

Africa (Cape Town)


Asia Pacific (Hong Kong)


{% raw %}

Europe (Milan)


{% raw %}

Middle East (Bahrain)


{% raw %}

China (Beijing)


{% raw %}

AWS GovCloud (US)


{% raw %}

All other Regions


{% raw %}

2. Export from instances

To export virtual machines for deployment to virtualized environments, AWS supports direct export from EC2 Instance using the AWS CLI.

Export virtual machines from EC2 Instance.

Please access the EC2 Management console to get the Instance ID information to export.

Image description

Run the command aws ec2 create-instance-export-task to launch the process of exporting EC2 Instance to the desired format for your virtualized environment. You need to enter the following parameters:

  • --instance-id: The Instance ID retrieved from the list of EC2 instances.
  • --target-environment: Target virtualization environment (eg microsoft)
  • --export-to-s3-task: Specify the exported virtual machine parameters:
    • Format (vhd)
    • S3 bucket storage (export-bucket-2021)
    • Storage path in the bucket (vms/)
    • To minimize the possibility of incorrect input, create a file named file.json to store the parameters passed to the parameter --export-to-s3-task
{% raw %}

{
"ContainerFormat": "ova",
"DiskImageFormat": "VMDK",
"S3Bucket": "export-bucket-2021",
"S3Prefix": "vms/"
}


Enter fullscreen mode Exit fullscreen mode

Image description

It will take some time to be able to export the instance to a VHD file used for deployment on a Hyper-V virtualized environment (or a VMDK file if you use VMWare Workstation). You can use aws ec2 describe-export-tasks command to check export progress



aws ec2 describe-export-tasks --export-task-ids <YourExportTaskID>


Enter fullscreen mode Exit fullscreen mode

Image description

Once done, you will have the virtual machine's files stored in the S3 bucket.

Image description

Deployment of exported virtual machine

After downloading the vhd hard disk file to the on-premise system, you can try to deploy the virtual machine using this vhd file.

3. Export virtual machine from AMI

Export virtual machine from EC2 AMI

To export virtual machines for deployment to virtualized environments, AWS supports exporting from AMI through the use of the AWS CLI.

Please access the EC2 Management console to get the AMI ID information to export.

Image description

Run the command aws ec2 export-image to launch the process of exporting the AMI to the desired format for your virtualized environment.

  • --image-id: The AMI ID retrieved from the list of EC2 instances.
  • --disk-image-format: Virtual machine hard disk/virtual machine file format (e.g. vmdk or vhdx)
  • --s3-export-location: Specify the location of the exported file:
  • S3 bucket storage (eg import-bucket-2021)
  • Storage path in the bucket (eg export/)

Image description

It will take some time to be able to export the AMI to a VHD file used for deployment on a Hyper-V virtualized environment (or a VMDK file if you use VMWare Workstation). You can use the aws ec2 describe-export-image-tasks command to check the export progress.



aws ec2 describe-export-image-tasks --export-image-task-ids <YourExportImageTaskID>


Enter fullscreen mode Exit fullscreen mode

Image description

Once done, you will have the virtual machine's disk file stored in the S3 bucket.

Image description

Deployment of exported virtual machine

After downloading the vhd hard disk file to the on-premise system, you can try to deploy the virtual machine using this vhd file.

4. Clean up resources

In this section, you will clean up resources on AWS Cloud to avoid incurring costs.
Delete the EC2 Instance created in the lab
- Access EC2 Management Console
- On the left navigation bar, select Intances
- Select all EC2 Instances related to the lab.
- Click Actions.
- Click Manage Instance State.
- Select Terminate.
- Click Change State.
Delete the Security Group created with EC2 Instance
- Access EC2 Management Console
- On the left navigation bar, select Security Groups
- Select all Security Groups related to the lab.
- Click Actions.
- Click Delete security groups
- Click Delete
Delete AMI
- Access EC2 Management Console
- On the left navigation bar, select AMIs
- Select the AMI related to the lab.
- Click Actions.
- Click Deregister.
- Click Continue.
Delete S3 Bucket
- Access S3 Management Console
- On the left navigation bar, select Buckets
- Select the Bucket related to the lab and delete all the content. Or, tick the Bucket related to the card and select Empty.
- When you see the Empty Bucket prompt, type permanently delete in the empty box.
- Select Exit.
- Tick the Bucket that has just been deleted and select Delete.
- When you get the Delete bucket prompt, type the name of the bucket you want to delete in the empty box.
- Select Delete Bucket.
- Repeat until all buckets related to the post are deleted.
With the IAM Role vmimport, you can keep it for future use.

The following sections

AWS Import/Export - Part 1: Import

AWS Import/Export - Part 2: Export VM from AWS

Top comments (3)

Collapse
 
junaayyeed profile image
Syed Junaid Hussain

Your articles on AWS Import/Export are amazing and detailed, I didn't found any other blog or article that is more accurate than this. This is amazing! Thank you soo much for sharing the details and all the steps. Kudos!