AWS Import/Export - Part 1: Import
Tags: aws, cloud, vmware, community
Published: 2023-03-04 21:18:00

#### Content of Table:

1. [Preparing the virtual machine]()
2. [Export virtual machine from On-premise]()
3. [Upload virtual machine to AWS]()
4. [Import virtual machine to AWS]()
5. [Deploy Instance from AMI]()


#### Overview

#### VM Import/Export

*VM Import/Export* is a service that allows you to import virtual machines (VMs) from your virtualized environment to Amazon EC2 and vice versa. This feature allows you to migrate applications and infrastructure resources from an on-prem virtualized environment to Amazon EC2, back up your virtual machines to EC2, and create an archive of virtual machines for redundancy, and recovery after the crash.

You can use VM Import/Export with no service charges (except for EC2 VMs and *S3 Bucket*).


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

#### AWS Simple Storage Service (S3)
*AWS S3* is a large data storage service, with a *S3 bucket* containing many *Objects*. You can store an object up to 5TB in size and there is no limit to the number of objects stored in a bucket.


In this step, you will perform the initialization of a virtual machine on your on-prem virtualization environment. The virtual machine that will be initialized is **Ubuntu Desktop**.
 
As part of the exercise, you will deploy virtual machines in a virtualized environment **VMWare Workstation** on-premise.

#### 1. Prepare virtual machine in virtualized environment VMWare Workstation

Install VMWare Workstation Pro at [Download WMWare Workstation Pro](https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html).

Download OS [Ubuntu](https://ubuntu.com/download/desktop)


Access VMWare Workstation, select **Create a New Virtual Machine**


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

At **Welcome to the New Virtual Machine WWizard**, select **Typical (recommended)**


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

In **Guest Operating System Insstallation**, select **Image file (.iso)** of the latest Ubuntu desktop version. You can download this file from the [Ubuntu Release] page (https://ubuntu.com/download/desktop)


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

At **Easy Install Innformation** enter **Username** as **awsstudent** and enter **password**.


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

At **Name the Virtual MMachine** name the virtual machine **Ubuntu**


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

At **Specify Disk Cacity** enter **20GB**


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

Review the parameters and select Finish to proceed with the installation.


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

Complete the **Ubuntu** installation in VMware.


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

User configuration.


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

After the installation and configuration process is complete, you install OpenSSH Server to connect SSH to this virtual machine with the following commands:

```
sudo apt install openssh-server
sudo systemctl start ssh
sudo systemctl enable ssh
```


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


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


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

#### 2. Export virtual machine from On-premise

In this step, we will export the virtual machine to use for the migration to the AWS platform.


Go to **VMWare Workstation**, select the newly created virtual machine, select **File**, and select **Export to OVF…**


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

Choose the location to save the export file


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

Wait about 5 minutes to export.


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

Access to the virtual machine export location, the file we use will be the **.vmdk** file


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

#### Upload virtual machine to AWS

In this step, we will use Amazon S3 to store the virtual machine file that has been exported from the virtualized environment.

#### Create S3 bucket to store virtual machines

To create an S3 bucket, we perform the following steps:

Access the Amazon S3 Management console.
- In the navigation bar, select Buckets.
- Select **Create bucket** to create a new S3 bucket.


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

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. (Example: import-bucket-2023)
- **Region**: Select the storage region of the bucket.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpua36lieoiksqgj1ahm.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/qmxxgxku2p4uuum7geqg.png)

Select **Create bucket**.


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

Successful bucket creation


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

#### 3. Upload virtual machine to S3 Bucket

After creating the bucket, we will proceed to upload the virtual machine file that we exported in the previous section.

- Access to the S3 bucket you created above. (Example: import-bucket-2023)
- In the **Objects** section, select **Upload**


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

Drag and drop the exported virtual machine file from the on-prem virtualization environment into the window or select Add files to select the virtual machine file. Then select **Upload**.
You create a virtual machine using VMWare Workstation, the virtual machine file in the example is Ubuntu-disk1.vmdk.



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

It will take some time for the file to be uploaded to the S3 bucket.


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

#### 4. Import virtual machine to AWS


In this step, you will create a role named **vmimport** and import the virtual machine that was uploaded to the S3 Bucket in the previous step into an AMI. The entire process will be handled with the AWS CLI.

#### Create vmimport role

Before performing the Import of virtual machines into AWS. You need to check the role required for this implementation.

Access the IAM Management console.
In the navigation bar, select Roles


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

If you do not see the vmimport role, proceed to create the vmimport role.
Create a file named trust-policy.json to allow the VM Import/Export service to accept your upcoming vmimport role.


```
{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": { "Service": "vmie.amazonaws.com" },
         "Action": "sts:AssumeRole",
         "Condition": {
            "StringEquals":{
               "sts:Externalid": "vmimport"
            }
         }
      }
   ]
}
```

Use the create-role command to create an IAM role named vmimport and assign **trust-policy.json** to the parameter **--assume-role-policy-document**

```
replace "E:\trust-policy.json" with the path to the trust-policy.json file on your environment

aws iam create-role --role-name vmimport --assume-role-policy-document "file://E:\trust-policy.json"
```


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

Check the created role.


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

See **Trust relationships**


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

Create a file role-policy.json containing the following policies to allow the IAM role to access buckets containing virtual machines to exercise the permissions in the "Action" section:. Inside:

- disk-image-file-bucket is the name of the S3 bucket used to store the exported files from onpremise (import-bucket-2023 in this example).
- export-bucket is the name of the S3 bucket used to export the ec2 instance that will be used for the Export VM from AWS later.


```
{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Effect": "Allow",
         "Action": [
            "s3:GetBucketLocation",
            "s3:GetObject",
            "s3:ListBucket" 
         ],
         "Resource": [
            "arn:aws:s3:::disk-image-file-bucket",
            "arn:aws:s3:::disk-image-file-bucket/*"
         ]
      },
      {
         "Effect": "Allow",
         "Action": [
            "s3:GetBucketLocation",
            "s3:GetObject",
            "s3:ListBucket",
            "s3:PutObject",
            "s3:GetBucketAcl"
         ],
         "Resource": [
            "arn:aws:s3:::export-bucket",
            "arn:aws:s3:::export-bucket/*"
         ]
      },
      {
         "Effect": "Allow",
         "Action": [
            "ec2:ModifySnapshotAttribute",
            "ec2:CopySnapshot",
            "ec2:RegisterImage",
            "ec2:Describe*"
         ],
         "Resource": "*"
      }
   ]
}
```

- Use the following command to assign the roles described in the role-policy.json file to the created vmimport role

```
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document "file://E:\role-policy.json"
```


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

Check permissions. You can also check to see if the vmimport role has been successfully created by going to the IAM Management Console and selecting the role. You can also edit the role policy directly by selecting Edit policy.


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

#### Import virtual machine to AMI
We will use the AWS CLI to launch the Import virtual machine to AMI process.


In Terminal on Linux (or Command Prompt/Power Shell on Windows), run the command aws ec2 import-image to start importing the exported virtual machine and convert it to AMI. The following settings are relevant:

- **--deescription**: Set description for AMI
- **--disk-ccontainers**: Contains information identifying virtual machine files such as:
- Format format (eg: vhdx or vmdk)
- Storage bucket (eg import-bucket-2023)
- File path (e.g. Ubuntu.vhdx or Ubuntu-disk1.vmdk)

```
aws ec2 import-image --description "VM Image" --disk-containers Format=vhdx,UserBucket="{S3Bucket=import-bucket-2021,S3Key=Ubuntu.vhdx}"
```


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


It will take 5-10 minutes depending on the size of the virtual machine for AWS to convert the virtual machine into an AMI.


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


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

Once completed, we will see in the AMI list there will be one more AMI with the AMI name being the task id we created above.


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

You must check that EBS is not **Encrypted**


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

#### 5. Deploy Instance from AMI

To deploy the virtual machine from the imported AMI, we perform the following steps:

To deploy the virtual machine from the imported AMI, we perform the following steps:

   - Access to EC2 Management console.
   - In the navigation bar, select AMIs.
   - Select the AMI you just imported from the virtual machine (eg import-ami-08a9efac866dfcb04). Then select Launch.


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

**Name**, enter **Import-Server**


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

Keep the default AMI.


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

Keep **Instance type** and select **Create new key pair**


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

Fill in the key pair information and select **Create key pair**


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

Leave the default **Network settings**


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

Select **View all instances**


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

Check the created instance.


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

Do SSH into the instance.


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

Select **SSH**


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

Complete SSH credentials.


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

Enter the password.


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

Complete SSH.


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

Test ping test.


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

### 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)