vagrant Getting started with vagrant Upload Vagrant Box image to Amazon AWS AMI


You have a local vagrant box that you want to upload to Amazon AWS. First, you need to create a .box file:

vagrant package --base my-virtual-machine

This step should take a while depending on the size of your image. Then, you need to get the .vmdk image from the .box file:

gunzip -S .box
tar xf package

After this step, you should have 4 new files: package, box-disk1.vmdk, Vagrantfile, and box.ovf. Now, to upload to AWS. Assuming you have a AWS account , create an S3 bucket to store the image on Amazon's servers. You're going to need Amazon's EC2 CLI for the next step (as you can't do this through the console as far as I can tell):

ec2-import-instance box-disk1_1.vmdk -f VMDK -t t2.micro -a x86_64 -b <S3-bucket-name> -o $AWS_ACCESS_KEY -w $AWS_SECRET_KEY -p Linux

This result of this command should take a while - it's uploading the big image file to S3, but the command itself returns more quickly. You can check on the progress of the import using the ec2-describe-conversion-tasks command.

Once that finishes, you'll see an instance of your box running in the AWS console. However, you might not be able to access it because it doesn't have a Public IP address and/or doesn't have a .pem file associated with it. So, the next step is to create an AMI from the instance. To create an AMI, stop the instance (don't terminate!) and right click the instance and go to Image->Create Image. This should take a while as well. You can check up on the progress in the AMIs view of the console. Once it finishes, launch an instance using the AMI attaching a .pem key file to it and then you can ssh in and you're good to go.