Wednesday, December 21, 2022

Migrating OnPremise VM to Amazon EC2

In this blog we are going to migrate OnPremise Virtual Machine to aws EC2.

Prerequisites:

  • IAM User with "Administrator" Access
  • AWS CLI installed on your machine & Configure "aws configure" 
  • Virtual Machine as "Oracle VM VirtualBox" and Etc.


Step 1) Export your Virtual Machine image with extention of OVA.

From AWS official documents here are some of the formats that you can use:

  • Open Virtualization Archive (OVA)
  • Virtual Machine Disk (VMDK)
  • Virtual Hard Disk (VHD/VHDX)
  • Open Virtualization Format (OVF)



Step 2) Create an S3 bucket (Ex: vm-machine-bucket)


Create an S3 bucket in the region where you will create your EC2.



Step 3) Create an IAM role named vmimport

To allow VM import/export service to perform some operation you should create a service role called ‘vmimport’.


  • Create a file named trust-policy.json on your computer. Add the following policy to the file:




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

  • Create another file named role-policy.json with the following policy, Don't forget to change your bucket name with existing one !



$ aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document "file://role-policy.json"


Step 4) Upload that exported image to S3 Bucket

$ aws s3 mv "/home/ubuntu/Documents/centos.ova" s3://vm-machine-bucket


Step 5) Import the VM image to AWS AMI Section

After you upload your VM image file to Amazon S3, you can use the AWS CLI to import the image.


  • Create another file named containers.json with the following policy.


Note : find S3 key name like: under your bucket



$ aws ec2 import-image --description "My On-Premise Centos VM" --disk-containers "file://containers.json"

After executing cmd you will output Which is as follows:

 



Step 6) Monitor an import image task

Note: Replace "import-ami-1234567890abcdef0" from above output ImportTaskId

$ aws ec2 describe-import-image-tasks --import-task-ids import-ami-1234567890abc7f744

  • Status values include the following:
  • active — The import task is in progress.
  • deleting — The import task is being canceled.
  • deleted — The import task is canceled.
  • updating — Import status is updating.
  • validating — The imported image is being validated.
  • validated — The imported image was validated.
  • converting — The imported image is being converted into an AMI.
  • completed — The import task is completed and the AMI is ready to use

Step 7) After Completed import image task, Let's check AMI section

Step 8) Finally ! Launch EC2 Instance through that AMI

 

 

1 comment:

testing