Content of Table:
- Preparing the virtual machine
- Export virtual machine from On-premise
- Upload virtual machine to AWS
- Import virtual machine to AWS
- 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).
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.
Download OS Ubuntu
Access VMWare Workstation, select Create a New Virtual Machine
At Welcome to the New Virtual Machine WWizard, select Typical (recommended)
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)
At Easy Install Innformation enter Username as awsstudent and enter password.
At Name the Virtual MMachine name the virtual machine Ubuntu
At Specify Disk Cacity enter 20GB
Review the parameters and select Finish to proceed with the installation.
Complete the Ubuntu installation in VMware.
User configuration.
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
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…
Choose the location to save the export file
Wait about 5 minutes to export.
Access to the virtual machine export location, the file we use will be the .vmdk file
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.
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.
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.
Select Create bucket.
Successful bucket creation
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
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.
It will take some time for the file to be uploaded to the S3 bucket.
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
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"
Check the created role.
See Trust relationships
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"
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.
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}"
It will take 5-10 minutes depending on the size of the virtual machine for AWS to convert the virtual machine into an AMI.
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.
You must check that EBS is not Encrypted
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.
Name, enter Import-Server
Keep the default AMI.
Keep Instance type and select Create new key pair
Fill in the key pair information and select Create key pair
Leave the default Network settings
Select View all instances
Check the created instance.
Do SSH into the instance.
Select SSH
Complete SSH credentials.
Enter the password.
Complete SSH.
Test ping test.
Top comments (0)