recepinanc
recepinanc

Reputation: 186

How to keep all instances in AWS Auto-scaling Group updated after deploying new code?

I am trying to build a more dynamic/scalable system in AWS. I have launched 2 instances in an AutoScaling group where the minimum number of instances is 2 and the maximum is 5 with a load balancer in front of them. I have enabled "Termination Protection" on the first two instances since they are going to be the ones that I use for deploying my Rails Application via Capistrano.

The problem is that I am not sure what is the best way to keep all instances in my autoscaling group up-to-date so they run the same version of the application.

I have searched for many techniques, below are the ones I find applicable but still do not know which would be the best.

1- AWS CodeDeploy: Looks pretty cool, using Blue/Green Deployment looks like it would do the job pretty solid with zero downtime. I do not know if there's a rule of thumb for this but in my opinion, the deployment time is a bit long, I am not sure if it would be applicable when I need to release a hotfix.

2- Via Script: I am not sure how to implement this using AWS either but, the idea is when a new code is uploaded to my 2 "master (?)" instances,

  1. I will create a new Launch Configuration using the new AMI
  2. Update the autoscaling group to use that new launch configuration
  3. Scale down my autoscaling group to terminate the instances that are running the old configuration
  4. Hopefully, autoscaling policies will create new instances using the new launch configuration

The problem with this approach is that it requires some manual operation which I do not want to rely on much.

3- Using User Data: Running new instances with user data that pulls the new version of the code. I do not think this is a good way since probably there will be other instances that are already running the old code.

So these are the solutions I have seen up to now, which one would be the best solution?

Cheers!

Upvotes: 4

Views: 1616

Answers (1)

recepinanc
recepinanc

Reputation: 186

I ended up using an extension gem (my app is written in ruby on rails) for deployment. I was already using Capistrano for deployment, then I found out the gem elbas which internally does the following:

  • Deploy your code to each running instance connected to a given AutoScale group
  • After deployment, create an AMI from one of the running instances
  • Attach the AMI with the new code to a new AWS Launch Configuration
  • Update your AutoScale group to use the new launch configuration
  • Delete any old AMIs created by ELBAS
  • Delete any old launch configurations created by ELBAS

This is basically the 2nd option (via Script option), and finding a gem that does this for me, removes the challenge of manually handling things.

Hope this helps, cheers!

Upvotes: 5

Related Questions