If you have OVF file, instead of OVA format, use any coversion tool.

I have downloaded and installed the VMware OVF tool from the VMware Web site. I have saved the VM as Ovf from the VMWare workstation console.

Go to the directory in which you have installed the tool and use the following command to covert the image to ova

ovftool E:\VMware\NN1\ovf\nagios.ovf E:\VMware\NN1\ovf\ova\nagios.ova

 

Upload the ova file to your s3 bucket. I have used the aws cli to perform this

Upload to s3 cli:
aws s3 cp nagios.ova s3://clouditspace

Create two json files as follows. These files are used for creating vmiport role and assign permissions

1. role-policy.json

{
“Version”:”2012-10-17″,
“Statement”:[
{
“Effect”:”Allow”,
“Action”:[
“s3:ListBucket”,
“s3:GetBucketLocation”
],
“Resource”:[
“arn:aws:s3:::clouditspace
]
},
{
“Effect”:”Allow”,
“Action”:[
“s3:GetObject”
],
“Resource”:[
“arn:aws:s3:::clouditspace/*”
]
},
{
“Effect”:”Allow”,
“Action”:[
“ec2:ModifySnapshotAttribute”,
“ec2:CopySnapshot”,
“ec2:RegisterImage”,
“ec2:Describe*”
],
“Resource”:”*”
}
]
}

 

Note that, I have used my bucket name as hilighted above

2. trust-policy.json

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Principal”: { “Service”: “vmie.amazonaws.com” },
“Action”: “sts:AssumeRole”,
“Condition”: {
“StringEquals”:{
“sts:Externalid”: “vmimport”
}
}
}
]
}

 

Now we are ready to imprt the ova file as EC2 AMI

CLI Command: Note to replace with suitable variables. My variables are highlighted

aws ec2 import-image –cli-input-json “{  \”Description\”: \”Manu_NagiosVM\”, \”DiskContainers\”: [ { \”Description\”: \”Manu_Nagios Import\”, \”UserBucket\”: { \”S3Bucket\”: \”clouditspace\”, \”S3Key\” : \”nagiosxi.ova\” } } ]}”

 

To check the status of the import job run the following cli command

aws ec2 describe-import-image-tasks

It shows in progress from the below status report

C:\Program Files\Amazon\AWSCLI>aws ec2 describe-import-image-tasks
{
“ImportImageTasks”: [
{
“Status”: “active”,
“Description”: “Manu_NagiosVM”,
“SnapshotDetails”: [
{
“UserBucket”: {
“S3Bucket”: “clouditspace”,
“S3Key”: “nagios.ova”
},
“DiskImageSize”: 1017712640.0,
“Description”: “Manu_Nagios Import”,
“Format”: “RAW”
}
],
“Progress”: “30”,
“StatusMessage”: “updating”,
“ImportTaskId”: “import-ami-04fc332817bd09a8b”
}
]
}
C:\Program Files\Amazon\AWSCLI>
If you have many such import tasks listed, use the below command to list the current task only (by filtering using the import task id)
Note the progress percentage also:
E:\VMware\nagios>aws ec2 describe-import-image-tasks –import-task-id import-ami-09b0abf8faa2aa095
{
“ImportImageTasks”: [
{
“Status”: “active”,
“Description”: “Manu_NagiosVM”,
“SnapshotDetails”: [
{
“UserBucket”: {
“S3Bucket”: “clouditspace”,
“S3Key”: “nagios.ova”
},
“DiskImageSize”: 287465984.0,
“Format”: “VMDK”
}
],
  “Progress”: “28”,
“StatusMessage”: “converting”,
“ImportTaskId”: “import-ami-09b0abf8faa2aa095”
}
]
}
E:\VMware\nagios>
Finally, you can see that the import is completed as below:
E:\VMware\nagios>aws ec2 describe-import-image-tasks –import-task-id import-ami-09b0abf8faa2aa095
{
“ImportImageTasks”: [
{
“Status”: “completed”,
“LicenseType”: “BYOL”,
“Description”: “Manu_NagiosVM”,
“ImageId”: “ami-02685e7af4017d4d1”,
“Platform”: “Linux”,
“Architecture”: “x86_64”,
“SnapshotDetails”: [
{
“UserBucket”: {
“S3Bucket”: “clouditspace”,
“S3Key”: “nagios.ova”
},
“DeviceName”: “/dev/sda1”,
“DiskImageSize”: 287465984.0,
“SnapshotId”: “snap-0de18f70d1a5abe4a”,
“Format”: “VMDK”
}
],
“ImportTaskId”: “import-ami-09b0abf8faa2aa095”
}
]
}
E:\VMware\nagios>
You may list the AMI imported by ‘self’ as below:
E:\VMware\nagios>aws ec2 describe-images –owners self
{
“Images”: [
{
“VirtualizationType”: “hvm”,
“Description”: “AWS-VMImport service: Linux – Red Hat Enterprise Linux Server release 6.4 (Santiago) – 2.6.32-358.el6.x86_64”,
“Hypervisor”: “xen”,
“ImageId”: “ami-02685e7af4017d4d1”,
“State”: “available”,
“BlockDeviceMappings”: [
{
“DeviceName”: “/dev/sda1”,
“Ebs”: {
“Encrypted”: false,
“DeleteOnTermination”: false,
“VolumeType”: “gp2”,
“VolumeSize”: 1,
“SnapshotId”: “snap-0de18f70d1a5abe4a”
}
}
],
“Architecture”: “x86_64”,
“ImageLocation”: “148488018616/import-ami-09b0abf8faa2aa095”,
“RootDeviceType”: “ebs”,
“OwnerId”: “148488018616”,
“RootDeviceName”: “/dev/sda1”,
“CreationDate”: “2018-04-22T09:17:22.000Z”,
“Public”: false,
“ImageType”: “machine”,
“Name”: “import-ami-09b0abf8faa2aa095”
}
]
}
E:\VMware\nagios>
Finally, you can use this ami to create your own EC2 in aws.

Leave a Reply

Your email address will not be published. Required fields are marked *