I’ve configured CD using CodePipeline & CodeDeploy.
- EC2 instances in Autoscaling Group (3 instances)
- Application Load Balancer with configured health check
- UWSGI applications on EC2 Instances
CodeDeploy Deployment Group Configuration:
- Assigned Application Load Balancer
- Targets Autoscaling Group (with attached Application Load Balancer).
- In-place deployment.
Then I have appspec, that has following hooks:
hooks: BeforeInstall: - location: scripts/clean_instance.sh timeout: 120 runas: root AfterInstall: - location: scripts/install_python_dependencies.sh timeout: 300 runas: project_user - location: scripts/compile_translations.sh timeout: 300 runas: project_user ApplicationStart: - location: scripts/start_application.sh timeout: 120 runas: project_user ApplicationStop: - location: scripts/stop_application.sh timeout: 120 runas: project_user When deployment is progressing users receive 5xx errors and it feels like if instances are not taken out from ALB. The documentation here https://docs.aws.amazon.com/en_us/codedeploy/latest/userguide/integrations-aws-elastic-load-balancing.html states, that
When you use an Elastic Load Balancing load balancer with an in-place deployment, instances in a deployment group are deregistered from a load balancer, updated with the latest application revision, and then reregistered with the load balancer as part of the same deployment group after the deployment is successful.
And I can see actual BlockTraffic and AllowTraffic events in deployment console. But then I’ve found this repository https://github.com/aws-samples/aws-codedeploy-samples/tree/master/load-balancing/elb-v2, which states that some custom scripts have to be executed to deregister instances from load balancer.
Should I actually use those scripts? If yes, then why documentation states, that ALB is not routing traffic on instances that are in the deployment process? If not, then why users encounter those 5xx errors while we deploy application?