Title: Transferring state before removal from load balancer (AWS)
Tags: amazon-web-services;amazon-ec2;autoscaling
Question: I have an application that maintains state where it is not practical to store the state on every state change.  When an AWS Auto Scaling group initiates a scale-in my plan was to then "transfer" the state to either disk or a memory grid.  I assumed using the Lifecycle Hooks I'd be able to tell the node it was going to be removed and then initiate that transfer.

However, it appears the hooks let me know AFTER the node is removed from the load balancer but before the instance is destroyed.  I'd like to be able to hook before the load balancer removes the node.  Is anyone aware of a way to do that?

Comment: Hi, can you elaborate on why it's important to know *before* ELB de-registers the instance? Is there a lengthy delay between that and the terminating lifecycle notification?

Comment: Not aware of an obvious solution here. Presumably it's not trivial for you to go fully stateless (https://gist.github.com/mlconnor/b8f2c2a8cb1a5ce25d66).

Comment: Lets say a user is connected to server A (session is local to A) - when the load balancer de-registers A the next request from the user will go to server B but the session will not have been transferred or shared yet.  On the other hand if we got a pre-de-registering hook, we could move the session to disk or distributed memory thus guaranteeing the session information is available to server B for the next request.

Comment: I dont think it is.  Our general issue is that the size of the session (and related in memory objects) is measured in multiple megabytes not kilobytes.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:11/29/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<amazon-web-services><amazon-ec2><autoscaling>', 'Title': 'Transferring state before removal from load balancer (AWS)', 'ViewCount': 31, 'id': 40875635, 'user_AboutMe': '', 'user_AccountId': 119047.0, 'user_DisplayName': 'gunygoogoo', 'user_Reputation': 611.0, 'user_Views': 65.0, 'user_id': 310490.0}}