Skip to content

AMI Roller

Description:

The AMI Roller tool is an automation script that was created to ease in updating launch templates for AWS auto scaling groups.

When executed the AMI roller performs the following actions.

  • Creates a new Amazon Machine Image of the web node
  • Creates a new version of the Launch Template that uses the AMI that was previously created
  • Set’s the new Launch Template version as the default version to be used by the web Auto Scaling Group

Application:

AMI’s or Amazon Machine Images are essentially snapshots or images of a machine disk. AMI’s need to be updated when changes to the web nodes have been made that need to be applied to any new web node that is launched.

Some examples include:

  • After modifying the php.env file.
  • When there is a significant difference in the site files that exist in the current (old) AMI versus the current state of the site files on the node. These differences happen as code changes are made, log files are rotated and version upgrades are made. Creating a new image with these changes included will reduce the amount of time needed for the html-sync process when a new node is spun up as part of the Auto Scaling Group.

Usage:

  1. Log into a web node instance that is a member of the Auto Scaling Group that needs to have the launch image updated
  2. execute the ami_roller command

Be aware the “Creating AMI…” process can take some time to complete, often several minutes. It is creating a full disk image.

$ ami_roller
Creating AMI...
AMI ID: ami-06f56fb721aae779b
Waiting for AMI to be available...
AMI is now available.
Creating new version of the launch template...
Setting new version of template to default
AMI roll complete, new auto-scaling nodes will use ami-06f56fb721aae779b
The new default template version is 5

The script does not launch new web nodes. This process need to be performed manually by either modifying the Auto Scaling Group configuration or by performing an Instance refresh. This should be done in order to ensure the new AMI/Launch Template are working as expected