How to Upload VM in Aws EC2 AMI






Uploading a VirtualBox VM to an Amazon EC2 AMI


image link.
We will learn How to uploading the VirtaulBox vm to an amazon ec2 ami because create the environment  like -- (staging servayer) in your VirtualBox and testing it the upload to Cloud (AWS) or May be current running servers in vm to move on AWS.
Login the EC2 Instance :--
Install AWS cli --
Note :-- If you are using Amazon Ami don't need to install cli in EC2 Instance and use another ami like - (Ami Market Place) use this Link to Install Aws Cli.
Create A IAM User to Access the Aws cli and Download the Access key and Secret Key.
Add the Keys in EC2 Intance.
Create the Files in Present Directory in EC2 Instance.
  1. trust-policy.json
  2. role-policy.json
  3. containers.jon
vim  trust-policy.json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "vmie.amazonaws.com" },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals":{
         "sts:Externalid": "vmimport"
      }
    }
  }]
}

Second File :--
vim  role-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListAllMyBuckets"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:CreateBucket",
        "s3:DeleteBucket",
        "s3:DeleteObject",
        "s3:GetBucketLocation",
        "s3:GetObject",
        "s3:ListBucket",
        "s3:PutObject"
      ],
      "Resource": ["arn:aws:s3:::bucketname","arn:aws:s3:::bucketname/*"]
    },
    {
      "Effect": "Allow",
      "Action": [
        "iam:CreateRole",
        "iam:PutRolePolicy"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:CancelConversionTask",
        "ec2:CancelExportTask",
        "ec2:CreateImage",
        "ec2:CreateInstanceExportTask",
        "ec2:CreateTags",
        "ec2:DeleteTags",
        "ec2:DescribeConversionTasks",
        "ec2:DescribeExportTasks",
        "ec2:DescribeInstanceAttribute",
        "ec2:DescribeInstanceStatus",
        "ec2:DescribeInstances",
        "ec2:DescribeTags",
        "ec2:ImportInstance",
        "ec2:ImportVolume",
        "ec2:StartInstances",
        "ec2:StopInstances",
        "ec2:TerminateInstances",
        "ec2:ImportImage",
        "ec2:ImportSnapshot",
        "ec2:DescribeImportImageTasks",
        "ec2:DescribeImportSnapshotTasks",
        "ec2:CancelImportTask"
      ],
      "Resource": "*"
    }
  ]
}
 

Create third file :--
vim containers.json
[
  {
    "Description": "my",
    "Format": "ova",
    "UserBucket": {
        "S3Bucket": "bucketname",
        "S3Key": "xyz.ova"
    }
}]

Please Create the Bucket and Upload the VM (VirtualBox Image) in Bucket.
Run the Commands Setup by Setup :-
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document file://role-policy.json
Note :-  This Command Add the Policy with S3 Bucket Access with VM by EC2 Instance.
aws ec2 import-image --description "my" --license-type BYOL --disk-containers file://containers.json
Note :- This Command Convert the VM to AMI From S3 Bucket with BYOL (Linux Machine VM) if not Linux Machine don't use this.
Output :-- the Command
{
    "Status": "active", 
    "LicenseType": "BYOL", 
    "Description": "my", 
    "SnapshotDetails": [
        {
            "UserBucket": {
                "S3Bucket": "vmupload123", 
                "S3Key": "apache1.ova"
            }, 
            "DiskImageSize": 0.0, 
            "Format": "OVA"
        }
    ], 
    "Progress": "2", 
    "StatusMessage": "pending", 
    "ImportTaskId": "import-ami-0d168e49de973434a"
}


Now the check the VM Convert to AWS AMI :-

aws ec2 describe-import-image-tasks --import-task-ids import-ami-0d168e49de973434a
Output :--
{
    "ImportImageTasks": [
        {
            "Status": "active", 
            "LicenseType": "BYOL", 
            "Description": "my", 
            "SnapshotDetails": [
                {
                    "Status": "active", 
                    "UserBucket": {
                        "S3Bucket": "vmupload123", 
                        "S3Key": "apache1.ova"
                    }, 
                    "DiskImageSize": 667214848.0, 
                    "Format": "VMDK"
                }
            ], 
            "Progress": "28", 
            "StatusMessage": "converting", 
            "ImportTaskId": "import-ami-0d168e49de973434a"
        }
    ]
}
Now Finally VM Converting to AWS AMI :-


Now also Verify to AMI in AWS Console :-






How to Upload VM in Aws EC2 AMI How to Upload VM in Aws EC2 AMI Reviewed by Unknown on August 29, 2018 Rating: 5

No comments:

Scribe

http://feeds.feedburner.com/LinuxAndAws
Powered by Blogger.
X

Get Updates On

Linux Tutorial

AWS Tutorial

Devops Tutorial

We are going to send you our resources for free. To collect your copy at first, join our mailing list. So don't miss any updates, stay connected!