In a previous post I wrote about how we can use Auto-Scaling Groups (ASG’s) to quickly adapt to user load. In this post I intend to explain a method to create custom Amazon Machine Image’s (AMI’s) using a project called packer.io
what is packer?
Packer is an open source tool for creating identical machine images for multiple platforms from a single source configuration. Packer is lightweight, runs on every major operating system and is able to create machine images for multiple platforms in parallel. Packer does not replace configuration management like Chef or Puppet. In fact, when building images, Packer is able to use tools like Chef or Puppet to install software.
A machine image is a single static unit that contains a pre-configured operating system and installed software which is used to quickly create new running machines. Machine image formats change for each platform. Some examples include AMIs for EC2, VMDK/VMX files for VMware, OVF exports for VirtualBox, etc.
Packer is distributed as a binary package for different OS’s. Our OS is Linux based with a 64-bit CPU.
Now that packer is installed lets create a json file to build an Amazon EC2 AMI.
And let’s make a shell script that will be executed to customize the AMI:
Now that we have these 2 files in our current directory lets build the AMI:
Packer gives us a method to consistently create base AMI’s that can be further configured with tools like Puppet. Packer ensures that these AMI’s are documented with code so that at later dates we can upgrade instances and know exactly how they were created. By using custom-built AMI’s you’re able to speed up the time it takes ASG to boot new instances.