Blue green deployments

I am new to AWS. I have been using Azure mostly. We have used App service to deploy an ASP.NET Web application in a sort of blue-green manner wherein we deploy to a staging slot and if everything is okay, we swap the deployment to production slot by the click of swap button. If something goes wrong, we do a swap again.

I have brought this under CI where all these processes are automatic:

  • Application is deployed to staging.
  • Automated tests are run on staging for verification as well as warm-up.
  • Swap the staging slot with Production.

Now, how do I achieve this using AWS? I have 3 web servers that serve an ASP.NET Web application. I have a load balancer to balance the load across these 3 servers.

Google gives several possibilities:

However, I am not sure how to pick a simple and best approach. It looks like we have to create a new VM image from scratch, install all our software, do the deployment for ‘green’ version, test it and then do a swap with the existing blue. And we create the new VMs using Cloud formation/Chef or any other tools. Is my understanding correct? Is there a simpler way to do this?


Related discussions:

I’m a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

^(If you follow any of the above links, please respect the rules of reddit and don’t vote in the other threads.) ^(Info ^/ [1](/message/compose?to=/r/TotesMessenger))


  1. Contact ↩︎

Beanstalk makes it easy

Hey bot, I have cross posted to devops as well. :slight_smile:

I’d suggest spinning up two ElasticBeanstalk environments and making use of the blue/green deployment functionality (CNAME swapping) that is built in already.

ElasticBeanstalk allows you to configure your instance using .ebextensions which will give you fine grained control over the instance and deployment lifestyle.

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

You may also find it worthwhile looking into Hashicorp Packer as that will allow you to build a custom AMI that will ensure all your instances are running the same packages. This is important when using auto scaling as you don’t want to suddenly deploy with a newer version of something that adversely affects your software.

https://www.packer.io/

Let me know if you need any more specifics.

Avoid beanstalk if you can. It is mostly an abstraction layer on top of cloudformation and prevents the use of a bunch of functionality. For .net in particular the advantages are rarely worth the sacrifices.

Your PaaS options in AWS are more limited than Azure, and you are going to need to take ownership of some OS level responsibility.

Baking OS images with something like packer is probably your best bet. Also looking at server 2016 for boot time improvements if you can’t run .net core.

Blue green can be done with route53 if you’re happy to do it at the dns level.

Looks like in case of Elastic Bean Stalk, I won’t be able to control the VMs. I need additional software to be installed in the VMs. How do I go about it?

As has been said, Elastic Beanstalk is the way to go in the way of a more managed service, anything else you will have to assemble yourself using Route 53, Load Balancers and EC2 Instances, perhaps with help of other third party tools.

Elastic Beanstalk is a good place to start also because of the ways you can choose to handle deployments with rollback strategies.

In our setup we usually do rolling deployments with additional batches of instances, which once healthy take over load from the previous instances which get terminated afterwards. We do that for most of the simple deployments. Whenever we have a more “risky” deployment that has a bigger chance of not working out in the following hours, then we use the blue/green approach.

What do you mean by “won’t be able to control the vms”?

What do you suggest? Can you list the steps, please: (Let me know if the following is correct, when 3 VMs + 1 Elastic Balancer are running.)

  • Use Packer or Cloud formation to create VMs from image. Image needs to be prepared before hand with all required software.
  • Add the resulting VMs to Elastic Load Balancer in unhealthy state
  • Use API call to make old VMs unhealthy and new VMs healthy.

Is it something that works? Sorry I don’t have much knowledge in AWS

You can use custom AMIs (VM snapshots that instances are created from) in Elastic Beanstalk. The defaults EB gives you for each language are just pre-configured AMIs provided by AWS (e.g. PHP is Amazon Linux + PHP + Apache2).

As /u/mcfishie said, take a look at Packer to build those AMIs from some sort of provisioning script (ansible, chef, puppet, etc. even shell). Then configure your EB environment to use the AMI that it creates.

For what it’s worth, Elastic Beanstalk could be a good fit so I wouldn’t discount it completely. Having used EB a bit, I find it to be very well suited for app deployments that I’m not extremely “intimate” with and that random people in my org will have to support. It’s nice in that it has lots of easy ways to do routine tasks like rebooting the app, getting logs and blue-green deployments like you are looking for. This is great for managing all those little web apps that mostly run without a hitch but maybe you have to upgrade every few months or reboot it now and then. EB is a time-saver and simplifying service for things like this, and prevents a ton of problems from being escalated from level 1.

That being said, if this is an app you want absolute full control over every aspect of and is something you work with every day, EB is probably not the right fit.

How is Docker for Windows working for people? If you were able to containerize your app, your staging process would not be needed anymore. You could test the new container build on another system, and then just swap the container on the prod systems. Then you can swap back to the old container if there are issues. No fiddling with multiple environments anymore.

However, I am not sure how to pick a simple and best approach. It looks like we have to create a new VM image from scratch, install all our software, do the deployment for ‘green’ version, test it and then do a swap with the existing blue.

Yes, but the requirement is that you use some sort of deployment mechanism to automate it. If you’re doing it manually, it’s not worth the effort.

OP, back when I used Elastic Beanstalk I did a lot of blue/green deployments using the following:

https://github.com/ThoughtWorksStudios/eb_deployer

It was very successful/beneficial at the time. Highly recommend if you go the EB route.

I’m not a fan of using DNS to swap between two load balancers and would rather assign a load balancer an Elastic IP and then assign it to the new deployment group.

What /u/melarenigma said. Here’s a graphic from the AWS ReInvent 2016 presentation on how to architect an app for million+ users:

It’s a simple graphic, but the graphic does have merit. Combined with Lambda, with CloudFormation, you can achieve manageable blue green deployments: https://blog.powerupcloud.com/blue-green-deployment-using-aws-cloudformation-and-lambda-1555054aab3a

AWS CodeDeploy can handle the blue-green deployment for you:
https://aws.amazon.com/blogs/devops/performing-bluegreen-deployments-with-aws-codedeploy-and-auto-scaling-groups/

You just have to provide the AMIs, the installation instructions and testing instructions and it will automatically deploy the application, reroute the traffic and rollback if something is not right.