Blue-Green Lambda function

Lambda for Blue-Green environment switchover

While reviewing the CodePipeline, review the stage that triggers Lambda execution to swap the target-group assignments for the listener ports. This stage will be triggered only when the preceeding stage gets an approval.

Blue Target Group is associated with Port 80 that represents Live/Production traffic and Green Target Group is associated with Port 8080 and is available for new version of the Application.

The new version of the application (green environment) can be tested by accessing the load balancer at port 8080, example http://LOAD_BALANCER_URL:8080 .If you want to restrict the traffic ranges accessing beta version of the code, you may modify the Ingress rules here.

Code Rollout:

  • During initial rollout, both Blue and Green service serve same application versions.
  • As you introduce new release, CodePipeline picks those changes and are pushed down the pipeline using CodeBuild and deployed to the Green service.
  • In order to switch from Green to Blue service (or from beta to Prod environment), you have to Approve the release by going to CodePipeline management console and clicking Review button.
  • Approving the change will trigger Lambda function (blue_green_flip.py) which does the swap of ALB Target Groups.
  • If you discover bugs while in Production, you can revert to previous application version by clicking and approving the change again. This in turn will put Blue service back into Production.

To simplify identifying which Target Groups are serving Live traffic, we have added Tags on ALB Target Groups. Target Group IsProduction Tag will say true for Production application.

The diagram below shows the backend mapping of Listener Ports <-> Target-Group being swapped after the approval.

bluegreen