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.
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;
}
# Run as a less privileged user for security reasons.
user nginx;
# Number of worker_threads to run;
# "auto" sets it to the #CPU_cores available in the system, and
# offers the best performance.
worker_processes auto;
events { worker_connections 1024; }
http {
server {
# Hide nginx version information.
server_tokens off;
listen 80;
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
location / {
return 404;
}
gzip on;
gzip_vary on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 256;
gunzip on;
}
}
cd ~/environment/nginx-example
git add .
git commit -m "Returning 404 error"
git push
80
Here is the command to get the url:
echo "http://$load_balancer_url"
// CloudWatch Alarms for 4XX errors
const blue5xxMetric = new cloudWatch.Metric({
namespace: 'AWS/ApplicationELB',
metricName: 'HTTPCode_Target_4XX_Count',
dimensions: {
TargetGroup: blueGroup.targetGroupFullName,
LoadBalancer: alb.loadBalancerFullName
},
statistic: cloudWatch.Statistic.SUM,
period: Duration.minutes(1)
});
const blueGroupAlarm = new cloudWatch.Alarm(this, "blue4xxErrors", {
alarmName: "Blue_4xx_Alarm",
alarmDescription: "CloudWatch Alarm for the 4xx errors of Blue target group",
metric: blue5xxMetric,
threshold: 1,
evaluationPeriods: 1
});
const green5xxMetric = new cloudWatch.Metric({
namespace: 'AWS/ApplicationELB',
metricName: 'HTTPCode_Target_4XX_Count',
dimensions: {
TargetGroup: greenGroup.targetGroupFullName,
LoadBalancer: alb.loadBalancerFullName
},
statistic: cloudWatch.Statistic.SUM,
period: Duration.minutes(1)
});
const greenGroupAlarm = new cloudWatch.Alarm(this, "green4xxErrors", {
alarmName: "Green_4xx_Alarm",
alarmDescription: "CloudWatch Alarm for the 4xx errors of Green target group",
metric: green5xxMetric,
threshold: 1,
evaluationPeriods: 1
});
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.