Using EC2 Auto-Scaling Groups with Fabric

Trying to deploy fabric recipes to an auto-scaling group on EC2 could prove pretty painful, except if you have this slick code snippet to define your server group in Fabric.

Basically I’m using boto to list all of the instances currently running in a specific security group, and then populate env.hosts.

This solves the problem for pushing to running hosts. In order to pull the latest codebase when a new instance fires up, we just stuck some scripts in /etc/rc.local — more on that later.