观察结果
当使用Amazon ELB应用程序负载均衡器并使用Sticky Sessions时,负载均衡器会在第一个请求中插入一个名为AWSALB
的cookie。为了让下一个请求坚持到相同的目标节点(EC2实例),cookie应该包含在该请求中。这样做时,负载平衡器似乎在对第二个请求的响应中插入了一个不同的cookie值。在第3个请求中包含此新的cookie值时,我们在响应中仍获得一个新的cookie值。依此类推...
(这与Sticky Sessions works with the Classic Load Balancer的Cookie命名为AWSELB
并保留其值直到被客户端或负载均衡器丢弃之前不同)。AWSALB
cookie始终更改值的原因似乎是(如docs所述):
The name of the cookie is AWSALB. The contents of these cookies are encrypted using a rotating key. You cannot decrypt or modify load balancer-generated cookies.
因此,即使Cookie的内容可能相同,也无法确定。
题
问题是对负载均衡器的请求是否必须始终包含
AWSALB
cookie的最新接收值,或者是否可以发送某些先前接收到的值(当然,是从同一粘性 session 发送的)。如果这是必需的,则AWS ELB应用程序负载均衡器将无法为执行多个并行请求的客户端(在收到第一个
AWSALB
cookie之后)提供服务,而只能为按顺序执行所有请求的客户端(一次提供一个) 。有人能对此有所启示吗?
最佳答案
在这里等待答复后,我向亚马逊提出了支持案例并得到了答复:
I understand that you would like to confirm if it is required to provide the latest stickiness cookie for every request.
You are right in noting that the behaviour is different between CLB and ALB. Due to the different functionality of Application Load Balancer to direct traffic to multiple Target Groups, each having its own stickiness, ALB encrypts the information needed to direct traffic and provides new cookie on each request. This ensures that different times for different groups are always respected correctly.
Clients can always obtain the latest cookie, as internally the information would ensure correct routing to the same target. If you want to reuse single cookie it is also possible, ALB will respect it and correctly route the traffic as per the stickiness in the cookie. I would not recommend using the same cookie for periods longer than 60 seconds though. This is to ensure that in case of target becoming unavailable you can acquire new cookie with new stickiness information that would route you to new target.
关于amazon-web-services - 是否需要最新的AWSALB cookie? (AWS ELB应用程序负载均衡器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49197688/