A company is migrating a legacy web application from a single server to multiple Amazon EC2 instances behind an Application Load Balancer (ALB). After the migration, users report that they are frequently losing their sessions and are being prompted to log in again.
Which action should be taken to resolve the issue reported by users?
- Confirm that the ALB is not in a Multi-AZ configuration.
- Configure an Amazon CloudFront distribution with the ALB as the origin.
- Deploy a Network Load Balancer in front of the ALB.
- Enable sticky sessions for the target group of EC2 instances.
Legacy applications designed to run on a single server frequently store session data locally. When these applications are deployed on multiple instances behind a load balancer, user requests are routed to instances using the round robin routing algorithm. Session data stored on one instance would not be present on the others. By enabling sticky sessions [1], cookies are used to track user requests and keep subsequent requests going to the same instance.
[1] https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html#sticky-sessions