I have an ECS Cluster (example-ecs-cluster) with an EC2 launch type ECS Service (example-ecs-service). I am trying to build a Blue/Green deployment type with Target Group Swapping from CodeDeploy which means the new code revision should be served firstly from test port and then it should be swapped with prod port. I created an ELB and attached two listeners associated to two different target groups. One Target Group (example-target-group) for prod with port 80 and one Target Group (example-target-group2) for test with port 8080. There is only one Task Definition. I can verify that when the deployment starts two different task revisions are getting created. So, my expectation is to see that new revision should be reachable from test port which is 8080 and once CodeDeploy reroutes traffic from Original task set to the Replacement task set it should be reachable from port 80. However, when a new deployment is starting both test port and prod port serves to the new revision at the same time which shouldn't happen.
ELB
- Listener 80 --> example-target-group
- Listener 8080 --> example-target-group2
I created an ECS service only with example-target-group
because CODE_DEPLOY deployment-controller-type services doesn't support multiple target groups.
aws ecs create-service --cluster example-ecs-cluster --service-name example-ecs-service --task-definition nodejs-hello-world-task-def --desired-count 1 --deployment-controller type=CODE_DEPLOY --launch-type EC2 --load-balancers targetGroupArn=arn:aws:elasticloadbalancing:us-east-1:548754742764:targetgroup/example-target-group/0f9efaeceb63ac61,containerName=nodejs-hello-world,containerPort=8080
I am trying to achieve this with only one EC2 instance with two maximum Tasks running (one with new revision and other one with old revision).
What is the preferred way to handle this scenario with using Target Group swapping? Thanks!