Rollback failed deployment

Introduce a breaking change

Here we will trigger an automated rollback by returning a 500 response code. The code deployment group has the CloudWatch alarm configured to detect and rollback a deployment with 5xx errors.

  • Edit the nginx.conf to return a 500 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 500;
Expand to see the complete nginx.conf

Push the code to the CodeCommit repository

cd ~/environment/nginx-example
git add .
git commit -m "Returning 500 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://$ALB_DNS"
  • You will notice the page returning 500 Internal Server error
  • We have configured CloudWatch alarms which will look for 5XX 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.