DEV Community

Van Hoang Kha for AWS Community Builders

Posted on • Updated 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)**  


 ```97ee7ab57cc9b5034f31e107741a968e595c0d7a19ec23330eae8d045a46edfb```



**Europe (Milan)**  


 ```04636d9a349e458b0c1cbf1421858b9788b4ec28b066148d4907bb15c52b5b9c```



**Middle East (Bahrain)**  


 ```aa763f2cf70006650562c62a09433f04353db3cba6ba6aeb3550fdc8065d3d9f```



**China (Beijing)**  


 ```834bafd86b15b6ca71074df0fd1f93d234b9d5e848a2cb31f880c149003ce36f```



**AWS GovCloud (US)**  


 ```af913ca13efe7a94b88392711f6cfc8aa07c9d1454d4f190a624b126733a5602```



**All other Regions**  


 ```c4d8eabf8db69dbe46bfe0e517100c554f01200b104d59cd408e777ba442a322```


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
{
"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 (1)

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!