How to implement blue-green deployment with one master branch I was told that they easy way out is to have two production branches, master/blue and master/green, git merge action triggers CI to deploy to the matching stacks. Is that possible to do it with single master branch?

Some more details about our stacks.


CloudFront, origin set to S3 bucket which serves all the front-end SPA (single page app) static assets.
SPA app talks to AWS API Gateway, which connects AWS Lambda.
AWS Lambda is responsible for db CRUD operations with DynamoDB.
Front-end app and Lambda function each has their own Git repo, Git master branch merge action triggers 2 Circle CI jobs, one copy front-end assets to S3 bucket, the other deploys Lambda with serverless framework.


For blue-green deploy, I'm thinking to have 2 instances of S3, API gateway and Lambda function. To make the blue-green switch, we'll need to change origin from one S3 bucket to another, then create invalidations to clear the cache.

To make the single production git branch blue-green deployment to work, Circle CI needs to know is the current active stack is blue or green, copy &amp; paste / deploy to the other stack, if Circle CI is not able to do that, the alternative that I could think of is to somehow put the checkout_current_active_stack action in the git precommit hook? To be specific:


(in the git precommit hook) send out a HTTP request to the current active stack API (AWS lambda function, which keep track of the current stack information)
deploy base on the return value ('blue' or 'green')
It is worth separating your Continuous Integration "Build" from your Continuous Deployment "Pipeline".  For the build portion, CircleCI seems to be your tool of choice, for the latter I recommend using something like AWS CodeDeploy which natively supports Blue-Green Deployments, for completeness you can use CircleCI to orchestrate AWS CodeDeploy:



Separating your pipeline phases has several benefits:


You only need to compile/test once from the master branch; then promote the packages through the Artefact Repository.
Your packages are stored forever in an Artefact Repository, for example Sonartype Nexus or JFrog Artifactory, this means you can reproduce an old build as you have the specific packages used for deployment.
CodeDeploy will handle the release patterns for you without having to think too much about how to achieve Blue-Green Deployments.


It is also worth stating that you can model the whole pipeline in Application Release Automation tools such as BuildMaster or Nolio.  Personally, I prefer to build my pipelines from multiple 3rd party SaaS solutions.