How to Import Virtual Machine Image into AWS
2016-06-03 06:47:30    439    0    0
jim

Prepare Virtual Machine

  • Install OS on VMware or VirtualBox

  • Startup OS, delete the symbolic link of grubenv, then copy the real grubenv file here, like this:

  1. cd /boot/grub2/
  2. rm f grubenv
  3. cp /boot/efi/EFI/centos/grubenv ./

Export VM and Upload into AWS

  • Shutdown OS, export image using OVA type.

  • Login AWS console, then upload this OVA image into S3 bucket, for example: vm-import

  • Create vmimport role

  1. aws iam create-role --role-name vmimport \
  2. --assume-role-policy-document file://trust-policy.json

Here is the content of trust-policy.json

  1. {
  2. "Version":"2012-10-17",
  3. "Statement":[
  4. {
  5. "Sid":"",
  6. "Effect":"Allow",
  7. "Principal":{
  8. "Service":"vmie.amazonaws.com"
  9. },
  10. "Action":"sts:AssumeRole",
  11. "Condition":{
  12. "StringEquals":{
  13. "sts:ExternalId":"vmimport"
  14. }
  15. }
  16. }
  17. ]
  18. }
  • Edit policy for vmiport
  1. aws iam put-role-policy --role-name vmimport \
  2. --policy-name vmimport \
  3. --policy-document file://role-policy.json

Here is the content of role-policy.json

  1. {
  2. "Version":"2012-10-17",
  3. "Statement":[
  4. {
  5. "Effect":"Allow",
  6. "Action":[
  7. "s3:ListBucket",
  8. "s3:GetBucketLocation"
  9. ],
  10. "Resource":[
  11. "arns3:::vm-import"
  12. ]
  13. },
  14. {
  15. "Effect":"Allow",
  16. "Action":[
  17. "s3:GetObject"
  18. ],
  19. "Resource":[
  20. "arns3:::vm-import/*"
  21. ]
  22. },
  23. {
  24. "Effect":"Allow",
  25. "Action":[
  26. "ec2:ModifySnapshotAttribute",
  27. "ec2:CopySnapshot",
  28. "ec2:RegisterImage",
  29. "ec2:Describe*"
  30. ],
  31. "Resource":"*"
  32. }
  33. ]
  34. }
  • Do the import task:
  1. aws ec2 import-image --cli-input-json '
  2. {
  3. "Description": "OS OVA",
  4. "DiskContainers": [
  5. {
  6. "Description": "CLI Task",
  7. "UserBucket":
  8. {
  9. "S3Bucket": "vm-import",
  10. "S3Key" : "os.ova"
  11. }
  12. }
  13. ]
  14. }
  15. '

Here, os.ova is the name of vmware image which has been uploaded to s3.
vm-import is the name of s3 bucket which restores vmware image.

  • Use this command to monitor the import process.
    When it shows like this, it means successful.
  1. aws ec2 describe-import-image-tasks
  2. {
  3. "ImportImageTasks": [
  4. {
  5. "Status": "completed",
  6. "LicenseType": "BYOL",
  7. "Description": "OS OVA",
  8. "ImageId": "ami-a440a5c4",
  9. "Platform": "Linux",
  10. "Architecture": "x86_64",
  11. "SnapshotDetails": [
  12. {
  13. "UserBucket": {
  14. "S3Bucket": "vm-import",
  15. "S3Key": "os.ova"
  16. },
  17. "SnapshotId": "snap-abcd2e33",
  18. "DiskImageSize": 974067200.0,
  19. "DeviceName": "/dev/sda1",
  20. "Format": "VMDK"
  21. }
  22. ],
  23. "ImportTaskId": "import-ami-ffik6b4s"
  24. }
  25. ]
  26. }

Pre: 使用Go实现TLS 服务器和客户端

Next: SMTP using net/mail with STARTTLS

439
Table of content