Rollback failed deployment

Introduce a breaking change

Here we will trigger an automated rollback by returning a 404 response code. Generally, the Application Load Balancer would catch this error, but for the sake of the demo, we are allowing that as an acceptable health check response.

  • Edit the nginx.conf to return a 404 error instead of default index.html

Modify the / location directive to look like the following:

listen  80;
root    /usr/share/nginx/html;
include /etc/nginx/mime.types;

location / {
    return 404;
Expand to see the complete nginx.conf

Push the code to the CodeCommit repository

cd ~/environment/nginx-example
git add .
git commit -m "Returning 404 error"
git push

The code push will trigger the CodePipeline


  • The CodeDeploy initiates the deployment as before
  • Once the Step 3 traffic shifting is started, we open the service in your browser on the Load Balancer port 80

Here is the command to get the url:

echo "http://$load_balancer_url"
  • You will notice the page returning 404 Not Found error
  • We have configured CloudWatch alarms which will look for 4XX errors from the ELB target groups
Expand to see the code
  • The CodeDeploy is configured to initiate automatic rollback if the CloudWatch Alarms are In Alarm state
  • The CodeDeploy will stop the deployment
  • CodeDeploy will now re-route the production traffic to original task set
  • Finally, CodeDeploy will terminate the replacement task set
  • Refresh the service on the browser and the original Green background deployment will be visible

That’s it. You have successfully completed a Blue/Green Deployment and done automatic rollback of a failed deployment. Let’s review the configurations files now.