I have a CloudFront distribution pointing to an Application Load Balancer, which is load balancing to ECS containers running a Django app. The ALB target group has stick sessions enabled using Application-based cookie, set to Django’s sessionid
cookie which is Django’s main “logged-in” user indicator.
All works well after the user logs in; Django sets the sessionid
cookie and the ALB sets AWSALBAPP-0
cookie to a different value for each response, and the session stays sticky to a single ECS container.
The problem is when I redeploy the app, and the containers stop. When the ALB directs traffic to new targets, I see the AWSALBAPP-0
cookie get set to _remove_
. Always after this, the cookie value stays as _remove_
and the session is no longer sticky – it round-robin load balances. I have to log out and log back in to reestablish stickiness.
Why is this happening?
AWS documentation says:
If a target fails or becomes unhealthy, the load balancer stops routing requests to that target, and chooses a new healthy target based on the chosen load balancing algorithm. The load balancer treats the session as now being “stuck” to the new healthy target, and continues routing requests to the new healthy target even if the failed target comes back.
But that contradicts my experience…