Introduction
Deploy without service interruption and rollback in 5 seconds if issues arise. Blue-Green deployment maintains two environments and instantly switches with the load balancer. Generate designs with Claude Code.
CLAUDE.md Blue-Green Rules
## Blue-Green Deployment Rules
### Environment Setup
- Blue: current production (live traffic)
- Green: new version standby
- Both share the same DB/Redis/SQS (Stateless)
- Which color is "live" managed by ALB listener
### Switching Procedure
1. Deploy new version to Green
2. Run smoke tests on Green
3. Switch ALB rule from Blue→Green
4. Monitor metrics for 10 minutes
5. Update Blue to new version (for next Green)
### Rollback Conditions
- Error rate > 1% (5 minutes)
- P99 > 2 seconds
- Health check failure
- Rollback = ALB rule change only (completes in 5 seconds)
Generated Blue-Green Deploy
# .github/workflows/blue-green-deploy.yml
jobs:
blue-green-deploy:
steps:
- name: Determine current live color
id: current
run: |
LIVE_COLOR=$(aws elbv2 describe-target-groups \
--load-balancer-arn ${{ secrets.ALB_ARN }} \
--query "TargetGroups[?contains(TargetGroupName, 'live')].TargetGroupName" \
--output text | grep -oE 'blue|green' | head -1)
echo "live_color=$LIVE_COLOR" >> $GITHUB_OUTPUT
echo "standby_color=$([ $LIVE_COLOR = blue ] && echo green || echo blue)" >> $GITHUB_OUTPUT
- name: Deploy to standby + smoke test
run: |
aws ecs update-service --cluster production-${{ steps.current.outputs.standby_color }} --service myapp --task-definition myapp-${{ inputs.image_tag }} --force-new-deployment
aws ecs wait services-stable --cluster production-${{ steps.current.outputs.standby_color }} --services myapp
STANDBY_URL=${{ secrets.STANDBY_URL }}
curl -sf "$STANDBY_URL/health" && curl -sf "$STANDBY_URL/ready"
- name: Switch ALB traffic
id: switch
run: |
STANDBY_TG_ARN=$(aws elbv2 describe-target-groups --names "myapp-${{ steps.current.outputs.standby_color }}" --query "TargetGroups[0].TargetGroupArn" --output text)
aws elbv2 modify-listener --listener-arn ${{ secrets.LISTENER_ARN }} --default-actions "Type=forward,TargetGroupArn=$STANDBY_TG_ARN"
echo "Traffic switched to ${{ steps.current.outputs.standby_color }}"
- name: Monitor 10 minutes
run: |
for i in {1..20}; do
sleep 30
ERROR_RATE=$(aws cloudwatch get-metric-statistics --namespace AWS/ApplicationELB --metric-name HTTPCode_Target_5XX_Count --start-time $(date -u -d '5 minutes ago' +%Y-%m-%dT%H:%M:%SZ) --end-time $(date -u +%Y-%m-%dT%H:%M:%SZ) --period 300 --statistics Sum --query "Datapoints[0].Sum" --output text 2>/dev/null || echo "0")
if (( $(echo "$ERROR_RATE > 50" | bc -l) )); then exit 1; fi
done
- name: Rollback on failure
if: failure() && steps.switch.outcome == 'success'
run: |
LIVE_TG_ARN=$(aws elbv2 describe-target-groups --names "myapp-${{ steps.current.outputs.live_color }}" --query "TargetGroups[0].TargetGroupArn" --output text)
aws elbv2 modify-listener --listener-arn ${{ secrets.LISTENER_ARN }} --default-actions "Type=forward,TargetGroupArn=$LIVE_TG_ARN"
echo "Rolled back to ${{ steps.current.outputs.live_color }}"
Summary
Design Blue-Green Deployment with Claude Code:
- CLAUDE.md — environment definitions, switching procedure, rollback conditions
- Smoke test standby environment before switching ALB traffic
- ALB rule change only for rollback (5 seconds, no ECS redeployment)
- DB schema changes in 3 phases for backward compatibility (both versions running)
Review blue-green deployment designs with **Code Review Pack (¥980)* using /code-review at prompt-works.jp*
myouga (@myougatheaxo) — Axolotl VTuber.
Top comments (0)