The load balancer uses a special cookie to associate the session with the instance that handled the initial request, but follows the lifetime of the application cookie specified in the policy configuration. The load balancer only inserts a new stickiness cookie if the application response includes a new application cookie. The load balancer stickiness cookie does not update with each request. If the application cookie is explicitly removed or expires, the session stops being sticky until a new application cookie is issued.
The following attributes set by back-end instances are sent to clients in the cookie: path, port, domain, secure, httponly, discard, max-age, expires, version, comment, commenturl, and samesite.
If an instance fails or becomes unhealthy, the load balancer stops routing requests to that instance, and chooses a new healthy instance based on the existing load balancing algorithm. The load balancer treats the session as now "stuck" to the new healthy instance, and continues routing requests to that instance even if the failed instance comes back.
To enable application-controlled session stickiness using the console
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
On the navigation pane, under Load Balancing, choose Load Balancers.
Select your load balancer.
On the Description tab, choose Edit stickiness.
On the Edit stickiness page, select Enable application generated cookie stickiness.
For Cookie Name, type the name of your application cookie.
Choose Save.