Home Projects Blog

Converting an EC2 instance into an .OVA file

A few days ago I found out it was possible to convert AWS EC2 instances into OVA files which can then be used to run in VMWare. It's pretty nifty and lets you work on things locally as opposed to needing an internet connection.

You'll need to do a few things before you can do this:

First you will need to configure the correct permissions on the S3 bucket in order to let the service to be able to write to the bucket.

$ aws s3api put-bucket-acl --bucket bucket_name --grant-read id="alphanumeric-id-string"
      aws s3api put-bucket-acl --bucket bucket_name --grant-write id="alphanumeric-id-string"

Replace alphanumeric-id-string with c4d8eabf8db69dbe46bfe0e517100c554f01200b104d59cd408e777ba442a322 which is the canonical account ID to let a region specific account write to the S3 bucket. Then you can run the command below, specifying your bucket name and path name:

$ aws ec2 create-instance-export-task --instance-id i-XXXXXXXXXXXXXXXXX \
      --target-environment vmware \
      --export-to-s3-task DiskImageFormat=vmdk,ContainerFormat=ova,S3Bucket=$$bucket_name$$,S3Prefix=$$path_name/$$

Next is the long part, waiting to convert the instance into an image, it took me around ~3 hours to convert mine. You can check on the status with:

 $ aws ec2 describe-export-tasks --export-task-ids export-i-XXXXXXXXXXXXXXXXX
  
  {
          "ExportTask": {
              "ExportTaskId": "export-i-XXXXXXXXXXXXXXXXX",
              "ExportToS3Task": {
                  "ContainerFormat": "ova",
                  "DiskImageFormat": "vmdk",
                  "S3Bucket": "$$bucket_name$$",
                  "S3Key": "$$path_name$$/export-i-XXXXXXXXXXXXXXXXX.ova"
              },
              "InstanceExportDetails": {
                  "InstanceId": "i-XXXXXXXXXXXXXXXXX",
                  "TargetEnvironment": "vmware"
              },
              "State": "active"
          }
      }

Finally, you can then download the .ova file from your S3 bucket. :)

Sidenote - If you own the AMI, then you can convert that directly using the guide here:
https://docs.aws.amazon.com/vm-import/latest/userguide/vmexport_image.html. However, it is more hassle as you need to use an account with the right role and policies.

References: