Enable session persistence for Lightsail load balancers
You can enable session persistence for your users. This is helpful if you're storing session information locally in the user's browser. For example, you might be running a Magento e-commerce application with a shopping cart on Amazon Lightsail. If you turn on session persistence, your users can add items to their shopping carts, leave the site, and still find the items in their carts when they come back.
You can also adjust the cookie duration using the AWS Command Line Interface (AWS CLI) or the Lightsail API.
Enable session persistence
-
In the left navigation pane, choose Networking.
-
Choose your load balancer to manage it.
-
Choose the Inbound traffic tab.
-
Choose Enable session persistence.
Adjust the cookie duration
You can also adjust the cookie duration for the persistent session. This is useful if you want to have a particularly long or short duration. For example, for many ecommerce sites the duration is quite long. This lets customers leave and come back without losing items in their shopping carts.
If you haven't done so already, set up the AWS CLI and configure it.
Configure the AWS Command Line Interface to work with Amazon Lightsail
-
Open a command prompt or a terminal window.
-
Type the following AWS CLI command to increase the cookie duration to three days (259,200 seconds).
aws lightsail update-load-balancer-attribute --load-balancer-name
LoadBalancerName
--attribute-name SessionStickiness_LB_CookieDurationSeconds --attribute-value 259200In the command, replace
LoadBalancerName
with the name of your load balancer.If successful, you should see the following response.
{ "operations": [ { "status": "Succeeded", "resourceType": "LoadBalancer", "isTerminal": true, "operationDetails": "SessionStickiness_LB_CookieDurationSeconds", "statusChangedAt": 1511758936.174, "location": { "availabilityZone": "all", "regionName": "us-west-2" }, "operationType": "UpdateLoadBalancerAttribute", "resourceName": "example-load-balancer", "id": "681c2bd9-9a51-402b-8ad2-12345EXAMPLE", "createdAt": 1511758936.174 } ] }