Convert Oracle Virtual box Images (.ova) to Amazon AMI images

Convert Oracle Virtual box Images (.ova) to Amazon AMI images

Step 1: Install AWS Cli

sudo apt install awscli

Step2 : Configure CLI with Access Key and Secret Key.

aws configure

Step 3: Upload your ovi images to an S3 Bucket

Note Down : BucketName, Filename (Key)

Step 4: Create containers.json file

sudo nano containers.json and paste below content after adding correct parameters

[
{
“Description”: “GeoNode4”,
“Format”: “ova”,
“UserBucket”: {
“S3Bucket”: “bucketName“,
“S3Key”: “filename.ova
}
}
]

Step 5: Create trust-policy.json file

nano trust-policy.json

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

Step 6 : create role-policy.json

sudo nano role-policy.json

{
“Version”:”2012-10-17″,
“Statement”:[
{
“Effect”: “Allow”,
“Action”: [
“s3:GetBucketLocation”,
“s3:GetObject”,
“s3:ListBucket”
],
“Resource”: [
“arn:aws:s3:::changehere“,
“arn:aws:s3:::changehere/” ] },

{ “Effect”: “Allow”, “Action”: [ “s3:GetBucketLocation”, “s3:GetObject”, “s3:ListBucket”, “s3:PutObject”, “s3:GetBucketAcl” ], “Resource”: [ “arn:aws:s3:::changehere“, “arn:aws:s3:::changehere/
]
},
{
“Effect”: “Allow”,
“Action”: [
“ec2:ModifySnapshotAttribute”,
“ec2:CopySnapshot”,
“ec2:RegisterImage”,
“ec2:Describe” ], “Resource”: “
}
]
}

Step 7 :Attach trust policy to a role

aws iam create-role –role-name vmimport –assume-role-policy-document “file://trust-policy.json”

Step 8 :Attach role policy to a role

aws iam put-role-policy –role-name vmimport –policy-name vmimport –policy-document “file://role-policy.json”

Step 9 : Create AMI Image

aws ec2 import-image –description “MBRSC Geonode4” –disk-containers file://containers.json

Note down the Import task Id which needed for knowing the status

Step 10 : Check status using below command by replacing image ID

aws ec2 describe-import-image-tasks –import-task-ids import-ami-05xxxxxxxxxxxxxx