AWS Import/Export - Part 2: Export VM from AWS
Tags: export, aws
Published: 2023-03-08 22:18:51

#### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i1zqbiyqjz1bwpbpvcf.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ziadir2u58z88ojvbjz.png)

Select **Create bucket**.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhmfgi5csaxe97lv1wlu.png)

Finish creating the bucket.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uyu2tlgpets0fm879r8e.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3e9khtj7t9fhit3b4nuk.png)

Select **ACLs enabled**, select **Save changes**.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/esqsoyp8xrv48ne9u4gn.png)

Select **Add grantee**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blfgrtguuwcqszsz3li3.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bepbxelmyapyb46i6nrr.png)


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

> **Africa (Cape Town)**  
> ```3f7744aeebaf91dd60ab135eb1cf908700c8d2bc9133e61261e6c582be6e33ee```
> 
> **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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kf2bfu8hxuamdogtuwu5.png)

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/"
}
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d43kr1ls06e3yztz5sj8.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b2azoj6pr45bkdxxcqsh.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/73lwdt72r2m42cgyth2u.png)

#### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rkldxf02tgfc2liu5hit.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8b93by85s017mwo9wj0.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqibr2nbgpobdgl39810.png)

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4silqhar5301i3sybyuw.png)


#### 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](https://dev.to/aws-builders/aws-importexport-part-1-import-1kpj)

[AWS Import/Export - Part 2: Export VM from AWS](https://dev.to/aws-builders/aws-importexport-part-2-export-vm-from-aws-lcm)