- Newest
- Most votes
- Most comments
Based on your description, I can see that you've set up a blue/green deployment with CodeDeploy, but there are some misunderstandings about how the process works with ECS and target groups.
In a CodeDeploy blue/green deployment with ECS, the process doesn't work exactly as you've described in your expected scenario. Here's what's actually happening:
-
When you perform a blue/green deployment with CodeDeploy, it doesn't alternate between your target groups as separate environments. Instead, both target groups are used simultaneously during the deployment process.
-
The issue you're seeing where both target groups show the same instance is expected behavior. In a CodeDeploy blue/green deployment, the same EC2 instance can be registered to multiple target groups. This is because the traffic shifting happens at the load balancer level, not by moving instances between target groups.
-
The traffic ratio remains at 100% to blue and 0% to green after deployment because CodeDeploy modifies these weights during the deployment process, but once the deployment is complete, it sets the production traffic back to the primary target group (in this case, your blue target group).
-
Regarding the termination of instances, in a CodeDeploy blue/green deployment with EC2/ASG, CodeDeploy creates a new Auto Scaling group for the green environment and terminates the old one after the specified wait time. However, your description suggests that this isn't happening correctly.
To resolve your issues:
-
Check your CodeDeploy service role permissions. The role needs sufficient permissions to manage Auto Scaling groups, EC2 instances, and load balancers. Your custom policy seems to have most of these permissions, but verify that there are no restrictions preventing instance termination.
-
Ensure your AppSpec file is correctly configured for blue/green deployments. The AppSpec file tells CodeDeploy how to handle the deployment, including which resources to use and how to route traffic.
-
Consider using the AWS Console or CLI to check the deployment logs and events to see if there are any errors or warnings during the deployment process, particularly during the termination phase.
-
If you want to alternate between blue and green environments with each deployment, you might need to modify your deployment process or consider using a different approach, such as creating a custom script that alternates the target group assignments between deployments.
Your current setup isn't necessarily problematic, but it might not be achieving what you expected. The behavior you're seeing with both target groups showing the same instance is normal for how CodeDeploy works with load balancers and target groups in a blue/green deployment.
Sources
CodePipeline step CodeDeploy using ECS blue/green fails at 'Rerouting production traffic to replacement task set' | AWS re:Post
Troubleshoot Amazon ECS deployment issues - AWS CodeDeploy
Why do new EC2 instances initially show as unhealthy in ALB Target Group during both blue-green deployments and autoscaling? | AWS re:Post
Questions about CodeDeploy and ECS | AWS re:Post
Instance is registering to the incorrect Target Group automatically when Deploying via CodeDeploy | AWS re:Post
Relevant content
- asked 2 years ago
- asked 3 years ago
