Import Machine Images Into AWS With Packer

Amazon Web Services (AWS) is still the most popular cloud platform and Packer provides great integration that enables users to import builds into AWS and convert them to Amazon Machine Images (AMI).

Hashicorp’s Packer tool has the unique ability to create machine images for multiple operating system platforms and then spit them out to multiple virtualization and cloud platforms. This enables IT operations to better manage a consistent OS across whatever provider a server is running on, not to mention a great tool for DevOps.

How it Works

While you actually use Packer and AWS initially to build an AMI, you can also use other tools to first build a machine image on say Vagrant/Virtualbox. Then you can take the OVF image and then use Packer post-processors to export the OVF and ultimately have it converted to an AMI. This may be a good idea if you are using other platforms besides AWS to run workloads.

For using the OVF to AWS method, Packer first uploads the OVF to an S3 bucket, and then calls AWS API’s to convert that to an AMI.

AWS Prerequisites

In AWS, there are certain prerequisites that must be configured in order for Packer to upload and convert the OVA. I will not cover these in the article but these steps are fairly simple to do if you have experience with AWS. This involves setting up an S3 bucket, creating a service role and configuring a policy.

Packer AWS Settings

There are several configuration options available to users in Packer for building and then exporting to AWS. For reference they can all be found on Packer’s reference page. The required options are the AWS access key, secret key, region, and s3 bucket name. Packer does a great job at doing the rest of the work for calling the API in the background.

In addition, users can choose settings such as AMI description, license type, AMI name, and add tags to the AMI.

Example Packer Template

In this Packer template example, I have my source OVF file “box.ovf”. My builder is the “virtualbox-ovf” type, meaning you must use an existing ovf file in your builder. I do not have any Packer provisioners in this template configured, but many user would likely want to do some provisioning to their OVF such as configuring settings or installing software. The buider will actually export into another ovf file. Then the “amazon-import” post-processor will run which will first add the exported ovf to an S3 bucket and them convert that to an AMI.

Read more at ipswitch.com

Leave a Reply

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