In my earlier post we have seen how to create free server on AWS. What if you want to migrate your on premises vm to AWS. This article will quickly guide you about how to migrate vm to AWS.
How to migrate vm to AWS
There are couple of steps you need to follow to migrate vm to AWS. However I will suggest you to go through these pre-requisites before you migrate vm to AWS.
Step 1: Install AWS Command line interface. Please follow this article to perform the installation.
Step 2: Create user in AWS with programmatic access. For this login to AWS console and go to IAM under “Security, Identity & Compliance” service. Click on User on the left pane. Then click on Add user button to create AWS user. In the next window use suitable user name and select “Programmatic access” option. Click on Next:Permissions button. Then select “Attach existing policies directly” options and select “AdministratorAccess” policy under policies options. Click on “Next:Review” button to review the setup. At the end select “Create user” option to create AWS user. In the next window you will see “Access key ID” and “Secret access key” which are required for configuration. You can also download it as CSV file.
Step 3: Configure AWS user in command line inter face. Follow below commands to configure AWS CLI.
aws configure
System will ask you about Access Key ID and your Secret Access Key. Also it will ask you about default region. Kindly input the keys captured in previous step.
To confirm the configuration, create sample security group using below command:
aws ec2 create-security-group --group-name uxtechno -- description "UxTechno group"
If you got new security group created then, you have successfully configured aws cli with user created.
Now you are good to go with further configuration.
Take vm backup using ovf method and upload to S3
Step 4: Take the ovf backup of the vm. That’s pretty straightforward. After backup is complete you will get one OVF file and vmdk file.
Step 5: In the next step you need to create S3 bucket in AWS and upload this vmdk file inside this bucket. Kindly follow below articles to perform the same:
Please note that, we have uploaded vcf file “rhel-disk1.vmdk” inside the bucket called “aws-import-dir” same has been used during the step 7.
Step 6: Create IAM role with name vmimport which will have access to this bucket.
aws iam create-role --role-name vmimport --assume-role-policy-document file://trust-policy.json
Make sure create following “trust-policy.json” file for this under same directory for this role creation.
- trust-policy.json file contents:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service":"vmie.amazonaws.com"}, "Action": "sts:AssumeRole", "Condition":{ "StringEquals":{ "sts:Externalid":"vmimport" } } } ] }
If everything is Ok system responds with below message:
Actual step to migrate vm to AWS
Step 7: In this command we will import this vmdk file on aws using below command:
aws ec2 import-image --cli-input-json "{ \"Description\": \"my linux image\",\"DiskContainers\": [ {\"Description\": \"my linux image\",\"User Bucket\":{ \"S3Bucket\":\"aws-import-dir\" ,\"S3Key\" :\"rhel-disk1.vmdk\"}}]}"
You get output similar to below if all things are Ok.
Please make sure you note down the import id which is “import-ami-fgmcdnjz” in this case. This import can be used to check the status of import activity and can be checked with below command:
aws ec2 describe-import-image-tasks --import-task-ids "import-ami-fgmcdnjz"
After this you can able to snapshot backup in AWS console within few seconds as below:
Then after few minutes you can able to check the AMI image successfully created in console as below:
Once the status becomes available you can launch in AWS. In case you don’t know how to launch AMI follow “How to Launch custom AMI in AWS” part of this article.
Leave a Reply