Search code examples
amazon-web-servicesamazon-ec2amazon-elbaws-code-deployblue-green-deployment

AWS CodeDeploy Blue/Green Deployment stuck?


I was performing AWS Blue/Green deployment to test a basic apache server and as CodeDeploy goes through 4 steps of B/G deployment it stuck at step 3 i.e, Routing traffic to replacement instances for about half-hour. I am not able to figure out what's wrong even after spending a long time and a couple of retries. I don't know whether my setup is correct or not. Here is my setup for B/G deployment.

  1. Created an autoscaling group named orginalautoscalinggroup with two instances.
  2. Creted two target groups one for original env and second for replacement env namely originaltargetgroup & replacementtargetgroup.
  3. Attached originaltargetgroup to be a part of originalautoscalinggroup.
  4. Created an application load balancer namely apploadbalancer and attached it with originaltargetgroup
  5. Now apploadbalancer is attached with originaltargetgroup which is attached with the originalautoscalinggroup.

My Codedeploy B/G configuration looks like this.

  1. Deployment Type: B/G
  2. Env configuration: Automatically copy Amazon EC2 Auto Scaling group
  3. Amazon EC2 Autoscaling group: originalautoscalinggroup
  4. Traffic rerouting: Reroute traffic immediately
  5. Termination policy: Terminate the original instances in the deployment group
  6. Deployment configuration: CodeDeployDefault.AllAtOnce
  7. Application load balancer.
  8. Target group: originaltargetgroup

I think I am not able to attach correct load balancer or target group. Please help.

Image1

Image2


Solution

  • Adding answer based on comments.

    Since the B/G deployment is failing during traffic rerouting, specifically at "Allow Traffic", instances are in "Unhealthy" state.

    If the required services are not running on EC2 and are not reachable, they will remain in unhealthy state and traffic cannot be redirected to them, hence deployment will fail.

    To make sure required services/processes are running on EC2 servers started by AutoScaling group, you

    1. Update the Launch Config/Template with "User Data" to execute the script on EC2 startup, which will install, configure and start the required services, say Nginx on port 80.
    2. You can create a custom AMI which has required application already installed in it and on EC2 startup, required service/process will start.

    This way, whenever a new EC2 is started by ASG, it will go into healthy state depending on time required to start the process. Once it is healthy, it will be ready to server the traffic and post that, old instances will get de-registered.

    Once old instances are de-registered, they may get terminated based on configurations in CodeDeploy.