Instructor: So, here is a short lecture
on how to use CloudFront with your ALB
when you have enabled sticky sessions.
So, say you have an Application Load Balancer
and a Target Group, and you've enabled sticky sessions
so that you want the same request from the same user
to go to the same backend EC2 instances.
So, you're set up CloudFront with an Edge Location
and you want the two to work together.
So, the solution is to forward the cookie
that controls the session affinity to the origin
for that, so that the session affinity still works.
Because if you don't, for this session, the cookie,
then obviously, it's not going to be passed on to the ALB.
And then, your session affinity is not going to work.
So concretely, the user will do a GET,
and will pass on a cookie,
and maybe you've set up the default cookie.
So, AWSALB equals whatever.
Then, CloudFront is going to be doing a whitelisting, okay,
on this cookie.
The AWSALB cookie, then the cookie is going
to be forwarded to the ALB.
That means the ALB will see the cookie.
And therefore, it will know to send the request to
the same EC2 instance all the time for the same user.
So that if another user has another, will pass on a request,
but this time, the cookie is still named,
of course, it was ALB, but the value is
going to be different because it's a different user.
Then that request, again,
will forward the value of that cookie,
and the ALB is going to forward that
to another EC2 instance.
And again, it will be a sticky session for that user.
So, this is a important set up to see because it makes sense
once you see it, but it's a trick to know, obviously.
So if you're using the ALB with sticky sessions
and CloudFront, please set a whitelisting on all cookies
or the cookie that is controlling the session affinity.
And also, as a security measure, you should set a TTL, okay?
For your cached request to a value lesser than
what the authentication cookie is.
But this is just, you know, very, very detailed,
and it's not something the exam will test you on.
So that's it for this lecture.
I hope you liked it.
And I will see you in the next lecture.