Node.Js 当 运行 在负载均衡器后面的 AWS ECS 上时,Express 应用程序不允许登录

Node.Js Express app doesn't allow log in when running on AWS ECS behind a Load Balancer

我在负载均衡器后面的 AWS ECS 集群上有一个 Node.Js 应用程序 运行。它通过亚马逊提供的 public DNS 面向互联网。

应用内有基于护照/快递的用户登录功能。

当我将它作为 1 个任务启动时,就可以为用户登录。

当我将它作为超过 1 个任务启动时,当它登录时(我可以在日志中看到它)它直接不通过其他函数并注销。

这里可能有什么问题?

似乎 sticky session 未启用,因此请求随机分布在两个不同的任务中,用户不存在会话。

粘性会话

Sticky sessions are a mechanism to route requests to the same target in a target group. This is useful for servers that maintain state information in order to provide a continuous experience to clients. To use sticky sessions, the clients must support cookies.

您可以在 LB attributes 下的 Load 负载均衡器中启用粘性会话。

load-balancer-target-groups sticky-sessions