- Newest
- Most votes
- Most comments
you can adjust your approach to handle scale-in events more effectively. ** 1.Detect Scale-In Events:** Implement a mechanism to detect when an instance is scheduled for termination due to a scale-in event triggered by the EC2 Auto Scaling group.
2.Pre-Drain Notification: Before the ELB starts draining connections from the instance, send a notification to the instance indicating that it will be deregistered from the ELB soon. This notification should give the instance enough time to gracefully handle existing WebSocket connections and inform clients to reconnect to other instances.
3.Handle Graceful Connection Closure: Upon receiving the pre-drain notification, your application running on the instance should start gracefully closing WebSocket connections. This involves informing connected clients to reconnect to other instances.
4.Update CodeDeploy Hooks: Adjust your BeforeBlockTraffic and BlockTraffic CodeDeploy hooks to account for the pre-drain notification. These hooks should wait for a shorter duration since the instance has already started gracefully closing connections.
**
5.Testing and Validation:** Thoroughly test your solution to ensure that WebSocket connections are gracefully handled during both deployment and scale-in events. Validate that clients can seamlessly reconnect to other instances without service interruption.
Do you need the target group (TG) associated with the ASG (for example, are you using ELB healthchecks on the ASG?)
If not, you might be able to just not mention the TG on the ASG so that ASG doesn't deregister the instances; and instead only specify the TG on the CodeDeploy Deployment Group. I haven't tested the new CodeDeploy termination hook on ASG yet, but if that workflow doesn't deregister the instance, you could have that as a step in your CodeDeploy scripts. The only major concern I can think of with this option is if you're trying to deregister many instances at once, you might face ELB API throttling on the Deregister calls.
Thank you! I have removed link between ASG and ELB and now deregistration is part of CodeDeploy workflow

I appreciate your effort in answering the question, but without technical details the answer does not look complete.