Skip to content

Instantly share code, notes, and snippets.

@nateware
Created November 2, 2012 00:53
  • Star 17 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nateware/3997958 to your computer and use it in GitHub Desktop.
Cheat sheet to create auto-scaling group behind ELB
  1. Create the appropriate VPC that your application is going to live in. Create subnets for each availability zone you want to use.

  2. Create VPC security group(s) for your auto-scaling instances. For example, if you're going to auto-scale web servers, create a "web" VPC security group.

  3. Go into AWS console and create an ELB. Easy wizard. Select HTTP and (if needed) HTTPS. Make sure it's associated with the VPC you created in step 1.

  4. Create an auto-scaling launch configuration from the CLI. The launch configuration has the AMI, size, and security group from step #2. The security group must be by ID not name ("sg-12345"):

       as-create-launch-config web --image-id ami-2e31bf1e --instance-type m1.medium \
           -g sg-7619041a --key root 
    
  5. Create an auto-scaling group that references this launch configuration. The CLI is cryptic and requires that you list the AZ's and VPC subnets as comma-delimited lists, in the same order, to 2 different flags. Also make sure to include the "web" load balancer you created in step #1:

       as-create-auto-scaling-group web -l web -z us-west-2c,us-west-2b,us-west-2a \
           --vpc-zone-identifier 'subnet-271b8b4e,subnet-2e1b8b47,subnet-291b8b40' \
           --load-balancers web --min-size 1 --max-size 10 
    
  6. From there, the autoscaling group will be correctly associated with the ELB, and the AWS console should reflect this. However, ELB will likely show all errors, since there is no software that will respond successfully to the ELB health check. Your choices are either to bundle AMI's that have the production code (bad), or use puppet/chef to call the mothership, or bundle a simple AMI that pulls down code from S3 and unzips it ala this simple approach

  7. As an alternative approach, rather than using AWS autoscaling, you could have an external program spin up instances, push software, and then associate them with the ELB. This has its own issues, such as you have to write your own sprinkling algorithm across AZ's, but it does help with the software push:

       ec2-run-instances ami-2e31bf1e -t m1.medium -z us-west-2c -s subnet-271b8b4e
       cap deploy
       elb-register-instances-with-lb --instances i-12345
    
@bestbear
Copy link

Thank you for your detailed write-up! Very helpful.

@ritksm
Copy link

ritksm commented Nov 1, 2014

great work

@sjesu
Copy link

sjesu commented Oct 20, 2017

This article helped me a lot. Thank You for posting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment