How to Cut Over Blue-Green Traffic With DNS Weighting From CI/CD
Weighted DNS shifts resolution from blue to green gradually, and rollback is just restoring the old weights.
When you cannot share a load balancer between environments, weighted DNS records move traffic between them. Point most weight at green once it is healthy, watch metrics, then complete the shift. Keep blue live so you can revert the weights instantly.
How it works
Two weighted records answer the same name, one per environment. Resolvers distribute clients by weight. Because DNS is cached, this shifts gradually rather than instantly, so plan around your TTL. Rollback is repointing the weights back to blue.
Shift Route 53 weighted records
aws route53 change-resource-record-sets --hosted-zone-id "$ZONE" --change-batch '{
"Changes": [
{"Action":"UPSERT","ResourceRecordSet":{
"Name":"app.example.com","Type":"A","SetIdentifier":"blue","Weight":10,
"AliasTarget":{"HostedZoneId":"'"$LB_ZONE"'","DNSName":"'"$BLUE_LB"'","EvaluateTargetHealth":true}}},
{"Action":"UPSERT","ResourceRecordSet":{
"Name":"app.example.com","Type":"A","SetIdentifier":"green","Weight":90,
"AliasTarget":{"HostedZoneId":"'"$LB_ZONE"'","DNSName":"'"$GREEN_LB"'","EvaluateTargetHealth":true}}}
]
}'Gate the shift on green health
steps:
- name: Verify green is healthy before shifting DNS
run: |
for i in $(seq 1 30); do
curl -fsS https://green-lb.example.com/healthz && exit 0
sleep 5
done
echo "green not healthy, aborting cutover"; exit 1
- run: ./shift-dns.sh --blue 10 --green 90Mind the TTL
Lower the record TTL (for example to 60 seconds) before a cutover so clients pick up weight changes quickly, and so a rollback propagates fast. EvaluateTargetHealth lets Route 53 stop sending traffic to an environment whose load balancer is unhealthy.