

# Distribute web traffic with Lightsail load balancers
<a name="understanding-lightsail-load-balancers"></a>

A Lightsail load balancer distributes incoming web traffic among multiple Lightsail instances, in multiple Availability Zones. Load balancing increases the availability and fault tolerance of the application on your instances. You can add and remove instances from your Lightsail load balancer as your needs change, without disrupting the overall flow of requests to your application.

With Lightsail load balancing, we create a DNS host name and route any requests sent to this host name to a pool of target Lightsail instances. You can add as many target instances to your load balancer as you like, as long as you stay within your Lightsail account quotas for total number of instances.

## Load balancer features
<a name="lightsail-load-balancer-features"></a>

Lightsail load balancers offer the following features:
+ **HTTPS encryption** — By default, Lightsail load balancers handle unencrypted (HTTP) traffic requests through port 80. Activate HTTPS encryption by attaching a validated Lightsail SSL/TLS certificate to your load balancer. This allows your load balancer to handle encrypted (HTTPS) traffic requests through port 443. For more information, see [SSL/TLS certificates](understanding-tls-ssl-certificates-in-lightsail-https.md).

  The following features are available after you activate HTTPS encryption on your load balancer:
  + **HTTP to HTTPS redirection** — Activate HTTP to HTTPS redirection to automatically redirect HTTP requests to an HTTPS encrypted connection. For more information, see [Configure HTTP to HTTPS redirection for your load balancer](amazon-lightsail-configure-load-balancer-https-redirection.md).
  + **TLS security policies** — Configure a TLS security policy on your load balancer. For more information, see [Configuring TLS security policies on your Amazon Lightsail load balancers](amazon-lightsail-configure-load-balancer-tls-security-policy.md).
+ **Health checking** — By default, health checks are performed on the attached instances at the root of the web application that is running on them. The health checks monitor the health of the instances so that the load balancer can send requests only to the healthy instances. For more information, see [Health checking for a Lightsail load balancer](understanding-lightsail-load-balancer-health-checking.md).
+ **Session persistence** — Configure session persistence if you're storing session information locally in your website visitors' browsers. For example, you might be running a Magento e-commerce application with a shopping cart on your load-balanced Lightsail instances. If your website visitors add items to their shopping carts, and then end their sessions, when they come back, the shopping cart items will still be there if you configured session persistence. For more information, see [Enable session persistence for a load balancer](enable-session-stickiness-persistence-or-change-cookie-duration.md).

## When to use load balancers
<a name="when-to-use-lightsail-load-balancers"></a>

You should use a load balancer when you have a website that has occasional spikes in traffic or hosts content that can create a lot of load on an instance when many visitors are using it at once. For example, if you have an image-heavy website, you can load balance the image requests with the other page requests. That way, your pages load faster and your users are happier.

You can use a load balancer to create a highly available website. *High availability* refers to how long your website or application stays up over a given time period. If you have ever experienced a site outage, then a load balancer might help you have more uptime. You can use a Lightsail load balancer to make your application highly available by adding target instances that are distributed across multiple Availability Zones.

*Fault tolerance* is a related concept. If your site continues to function even after one of your instances or your database fails, it is considered tolerant. A load balancer can help you create a fault tolerant application or website.

## Recommended applications for load balancing
<a name="which-applications-are-good-for-load-balancing"></a>

Not all Lightsail applications need load balancers. If you decide to create a load-balanced application, you must configure your application first. For example, to prepare a LAMP stack application for load balancing, you should first create a centralized, dedicated database for all the target instances to read from and write to. You might also consider creating centralized media storage, such as a Lightsail object storage bucket. For more information, see [Configure an instance for load balancing](configure-lightsail-instances-for-load-balancing.md).

## Get started using load balancers
<a name="get-started-using-lightsail-load-balancers"></a>

You can [create a load balancer](create-lightsail-load-balancer-and-attach-lightsail-instances.md) using the Lightsail console, the AWS Command Line Interface (AWS CLI), or the Lightsail API. You must also [configure your instances for load balancing](configure-lightsail-instances-for-load-balancing.md).

After you create your load balancer and attach your configured instances, you can enable HTTPS using the following topic. For more information, see [Create an SSL/TLS certificate for your load balancer](create-tls-ssl-certificate-and-attach-to-lightsail-load-balancer-https.md).

# Distribute web traffic with a Lightsail load balancer
<a name="create-lightsail-load-balancer-and-attach-lightsail-instances"></a>

Create a load balancer to add redundancy to your application or to handle more web traffic. After the load balancer is created, you can attach the Lightsail instances that you want to balance. To learn more, see [Load balancers](understanding-lightsail-load-balancers.md)

## Prerequisites
<a name="create-lightsail-load-balancer-prerequisite"></a>

Before you begin, make sure you've prepared your Lightsail instances for load balancing. For more information, see [Configure an instances for load balancing](configure-lightsail-instances-for-load-balancing.md).

## Create a load balancer
<a name="create-lightsail-load-balancer"></a>

1. Sign in to the [Lightsail console](https://lightsail.aws.amazon.com/).

1. Choose the **Networking** tab.

1. Choose **Create load balancer**.

1. Confirm the AWS Region where the load balancer will be created, or choose **Change region** to select a different region.
**Note**  
By default, the load balancer will be created with port 80 open to accept HTTP requests. After the load balancer is created, you can create an SSL/TLS certificate and configure HTTPS. For more information, see [Create an SSL/TLS certificate for your load balancer](create-tls-ssl-certificate-and-attach-to-lightsail-load-balancer-https.md)

1. Enter a name for your load balancer.

   Resource names:
   + Must be unique within each AWS Region in your Lightsail account.
   + Must contain 2 to 255 characters.
   + Must start and end with an alphanumeric character or number.
   + Can include alphanumeric characters, numbers, periods, dashes, and underscores.

1. Choose one of the following options to add tags to your load balancer:
   + **Add key-only tags** or **Manage tags** (if tags have already been added). Enter your new tag into the tag key text box, and press **Enter**. Choose **Save** when you’re done entering your tags to add them, or choose **Cancel** to not add them.  
![\[Key-only tags in the Lightsail console.\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/amazon-lightsail-key-only-tags.png)
   + **Create a key-value tag**, then enter a key into the **Key** text box, and a value into the **Value** text box. Choose **Save** when you’re done entering your tags, or choose **Cancel** to not add them.

     Key-value tags can only be added one at a time before saving. To add more than one key-value tag, repeat the previous steps.  
![\[Key-value tags in the Lightsail console.\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/amazon-lightsail-key-value-tag.png)
**Note**  
For more information about key-only and key-value tags, see [Tags](amazon-lightsail-tags.md).

1. Choose **Create load balancer**.

## Attach an instance to your load balancer
<a name="attach-lightsail-instances-to-load-balancer"></a>

After your load balancer is created, Lightsail takes you to the load balancer management page. If you need to find that page again, choose the **Networking** tab on the Lightsail home page, and then choose the name of your Lightsail load balancer to manage it.

**Note**  
Your Lightsail instance must be running before you can successfully attach it to your load balancer.

1. On the load balancer management page, choose **Target instances**.

1. Choose an instance in the **Target instances** drop-down menu.

1. Choose **Attach**. Attachment can take several minutes.

   Attach another instance to the load balancer by choosing **Attach another**, and then repeating the preceding steps.

## Next steps
<a name="create-load-balancer-attach-instances-next-steps"></a>

After the load balancer is created, and your instances are attached, complete the following next steps to configure your load balancer:
+ [Create an SSL/TLS certificate for your load balancer](create-tls-ssl-certificate-and-attach-to-lightsail-load-balancer-https.md)
+ [Customize health checks for your load balancer](enable-set-up-health-checking-for-lightsail-load-balancer-metrics.md)

If you experience issues with your load balancer, see [Troubleshoot your load balancer](troubleshooting-lightsail-load-balancer-issues.md)

# Customize Lightsail load balancer health checks and HTTPS settings
<a name="update-settings-for-lightsail-load-balancer-health-check-path-https-session-stickiness-persistence-cookie-duration"></a>

When you create a Lightsail load balancer, you choose the AWS Region and the name. This topic instructs you how to update your load balancer to enable more options.

If you haven't done so already, you will need to create a load balancer. [Create a load balancer](create-lightsail-load-balancer-and-attach-lightsail-instances.md)

## Health checks
<a name="instance-health-checking"></a>

The first thing you're going to want to do is [Configure an instance for load balancing](configure-lightsail-instances-for-load-balancing.md). Once that's done, you can attach an instance to your load balancer. Attaching an instance starts the health checking process, and you get a **Passed** or **Failed** message on the load balancer management page.

![\[Health check status indicator\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/target-instances-health-check-passed.png)


You can also customize your health check path. For example, if your home page loads slowly or has a lot of images on it, you can configure Lightsail to check a different page that loads faster. [Customize load balancer health check paths](enable-set-up-health-checking-for-lightsail-load-balancer-metrics.md)

## Encrypted traffic (HTTPS)
<a name="enable-https-by-attaching-an-ssl-tls-certificate"></a>

You can set up HTTPS to create a more secure experience for your website users. It's a three-step process to create and validate an SSL/TLS certificate once you set up your load balancer.

 [Learn more about HTTPS](understanding-tls-ssl-certificates-in-lightsail-https.md) 

## Session persistence
<a name="load-balancer-session-persistence"></a>

Session persistence is useful 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 Lightsail. If you turn on session persistence, your users can add items to their shopping carts,end their sessions, and still find the items in their carts when they come back.

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 more information, see [Enable session persistence for a load balancer](enable-session-stickiness-persistence-or-change-cookie-duration.md).

# Configure Lightsail instances for load balancing
<a name="configure-lightsail-instances-for-load-balancing"></a>

Before you attach instances to your Amazon Lightsail load balancer, you need to evaluate your application's configuration. For example, load balancers often work better when the data tier is separated from the rest of the application. This topic tells you about each Lightsail instance and makes recommendations about whether to load balance (or *horizontally scale*) and how to best configure your application.

## General guidelines: Applications that use a database
<a name="applications-that-use-a-database"></a>

For Lightsail applications that use a database, we recommend that you separate the database instance from the rest of your application, so that you only have one database instance. The main reason is that you want to avoid writing data to more than one database. If you don't create a single database instance, then the data will be written to the database on whichever instance the user happens to hit.

## WordPress
<a name="configure-wordpress-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes, for either a WordPress blog or website. 

 **Configuration recommendations before using a Lightsail load balancer** 
+ Separate your database so that every WordPress instance running behind the load balancer is storing and retrieving information from the same place. If you need more performance from your database, you can replicate or change the processing power or memory independently of your web server.
+ Offload your files and static content to a Lightsail bucket. To do this, you must install the WP Offload Media Lite plugin on your WordPress website and configure it to connect to your Lightsail bucket. For more information, see [Tutorial: Connect a WordPress instance to a storage bucket](amazon-lightsail-connecting-buckets-to-wordpress.md).

## Node.js
<a name="configure-node-js-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes, with some considerations.

 **Configuration recommendations before using a Lightsail load balancer** 
+ In Lightsail, the Node.js stack packaged by Bitnami contains Node.js, Apache, Redis (an in-memory database), and Python. Depending on the application you're deploying, you can load balance across a few servers. However, you would need to configure a load balancer to balance the traffic among all the web servers and move Redis to another server.
+ Split the Redis server to another server to communicate with all the instances. Add a database server, if necessary.
+ One of the primary use cases for Redis is to cache data locally so you don't have to constantly hit the central database. We recommend that you enable session persistence to leverage the performance improvement from Redis. For more information, see [Enable session persistence for a load balancer](enable-session-stickiness-persistence-or-change-cookie-duration.md).
+ You can also have a shared Redis node, so you can also share a node or use a local cache on each machine using session persistence.
+ Consider including the `mod_proxy_balancer` in the Apache server, if you want to deploy a load balancer using Apache.

For more information, see [Scaling Node.js applications](https://www.freecodecamp.org/news/scaling-node-js-applications-8492bd8afadc).

## Magento
<a name="configure-magento-application-for-lightsail-load-balancer"></a>

**Horizontally scale? ** Yes.

 **Configuration recommendations before using a Lightsail load balancer** 
+ You can use an AWS reference deployment of Magento that uses additional components, such as an Amazon RDS database: [Terraform Magento Adobe Commerce on AWS](https://aws.amazon.com/quickstart/terraform-modules/magento-commerce/).
+ Be sure to enable session persistence. Magento uses a shopping cart, and this helps ensure that customers who make multiple visits across more than one session will retain items in their shopping carts when they return for a new session. For more information, see [Enable session persistence for a load balancer](enable-session-stickiness-persistence-or-change-cookie-duration.md).

## GitLab
<a name="configure-gitlab-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes, with considerations.

 **Configuration recommendations before using a Lightsail load balancer** 

You must have the following: 
+ A Redis node running and ready to use
+ A shared network storage server (NFS)
+ A centralized database (MySQL or PostgreSQL) for the application. See the general guidelines about databases, above.

For more information, see [High Availability](https://docs.gitlab.com/ee/administration/reference_architectures/#high-availability-ha)on the *GitLab* website.

**Note**  
The shared network storage server (NFS) referred to above, is not currently available with the GitLab blueprint.

## Drupal
<a name="configure-drupal-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes. Drupal has an official document describing how to horizontally scale your application: [Server Scaling](https://www.drupal.org/docs/managing-site-performance-and-scalability/server-scaling).

 **Configuration recommendations before using a Lightsail load balancer** 

You must set up a Drupal module to synchronize files among different instances. The Drupal website features several modules, but they may be more suitable for prototyping as opposed to production use.

Use a module that lets you store your files in Amazon S3. This gives you a centralized place for your files, rather than keeping separate copies on each target instance. That way, if you edit your files, the updates get picked up from the centralized store and your users see the same files, regardless of which instance they hit.
+  [Amazon S3 File System](https://www.drupal.org/project/s3fs) 
+  [Content Synchronization](https://www.drupal.org/project/content_sync) 

For more information, see [Scaling Drupal horizontally and in cloud](https://www.slideshare.net/burgerboydaddy/scaling-drupal-horizontally-and-in-cloud).

## LAMP stack
<a name="configure-lamp-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes. 

 **Configuration recommendations before using a Lightsail load balancer** 
+ You should create a database on a separate instance. All the instances behind the load balancer should point to this separate database instance so they store and retrieve information from the same place.
+ Depending on the application that you want to deploy, think about how to share the file system (NFS, Lightsail block storage disks, or Amazon S3 storage).

## MEAN stack
<a name="configure-mean-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes. 

 **Configuration recommendations before using a Lightsail load balancer** 

Move MongoDB to another machine and configure a mechanism to share the root document among the Lightsail instances.

## Redmine
<a name="configure-redmine-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes. 

 **Configuration recommendations before using a Lightsail load balancer** 
+ Get the [Redmine\$1S3 plugin](http://www.redmine.org/plugins/redmine_s3) to store the attachments on Amazon S3 instead of on the local file system.
+ Separate the database to a different instance.

## Nginx
<a name="configure-nginx-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes. 

You can have one or more Lightsail instances running Nginx and attached to a Lightsail load balancer. For more information, see [Scaling Web Applications with NGINX, Part 1: Load Balancing](https://www.nginx.com/blog/scaling-web-applications-nginx-part-load-balancing/).

## Joomla\$1
<a name="configure-joomla-application-for-lightsail-load-balancer"></a>

**Horizontally scale?** Yes, with considerations. 

 **Configuration recommendations before using a Lightsail load balancer** 

Although there is no official documentation on the Joomla website, there are some discussions on their community forums. Some users managed to horizontally scale their Joomla instances having a cluster with the following configuration:
+ A Lightsail load balancer configured to enable session persistence. For more information, see [Enable session persistence for a load balancer](enable-session-stickiness-persistence-or-change-cookie-duration.md).
+ Several Lightsail instances running Joomla attached to the load balancer with the document root of Joomla\$1 synchronized. You can do this using tools like Rsync, having an NFS server that is in charge of synchronizing the content among all Lightsail instances, or sharing files using AWS.
+ Several database servers configured with a replication cluster.
+ The same cache system configured in each Lightsail instance. There are some useful extensions, such as [JotCache](https://extensions.joomla.org/extension/jotcache/).

# Configure TLS security policies for your Lightsail load balancer
<a name="amazon-lightsail-configure-load-balancer-tls-security-policy"></a>

After you enable HTTPS on your Amazon Lightsail load balancer, you can configure a TLS security policy for the encrypted connections. This guide provides information about the security policies that you can configure on Lightsail load balancers, and the procedures for updating your load balancer's security policy. For more information about load balancers, see [Load balancers](understanding-lightsail-load-balancers.md).

## Security policies overview
<a name="load-balancer-security-policies-overview"></a>

Lightsail load balancing uses a Secure Socket Layer (SSL) negotiation configuration, known as a security policy, to negotiate SSL connections between a client and the load balancer. A security policy is a combination of protocols and ciphers. The protocol establishes a secure connection between a client and a server and ensures that all data passed between the client and your load balancer is private. A cipher is an encryption algorithm that uses encryption keys to create a coded message. Protocols use several ciphers to encrypt data over the internet. During the connection negotiation process, the client and the load balancer present a list of ciphers and protocols that they each support, in order of preference. By default, the first cipher on the server's list that matches any one of the client's ciphers is selected for the secure connection. Lightsail load balancers do not support SSL renegotiation for client or target connections.

The `TLS-2016-08` security policy is configured by default when you enable HTTPS on a Lightsail load balancer. You can configure a different security policy as needed, as described later in this guide. You can choose the security policy that is used for only for front-end connections. The `TLS-2016-08` security policy is always used for backend connections. Lightsail load balancers do not support custom security policies.

## Supported security policies and protocols
<a name="load-balancer-supported-policies"></a>

Lightsail load balancers can be configured with the following security policies and protocols:

![\[Supported TLS security policies\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/amazon-lighstail-load-balancer-tls-protocols.png)


## Complete the prerequisites
<a name="configure-load-balancer-security-policy-prerequisites"></a>

Complete the following prerequisites if you haven't already:
+ Create a load balancer and attach instances to it. For more information, see [Create a load balancer and attach instances to it](create-lightsail-load-balancer-and-attach-lightsail-instances.md).
+ Create an SSL/TLS certificate and attach it to your load balancer to enable HTTPS. For more information, see [Create an SSL/TLS certificate for your Lightsail load balancer](create-tls-ssl-certificate-and-attach-to-lightsail-load-balancer-https.md). For more information about certificates, see [SSL/TLS certificates](understanding-tls-ssl-certificates-in-lightsail-https.md).

## Configure a security policy using the Lightsail console
<a name="configure-load-balancer-security-policy-console"></a>

Complete the following procedure to configure a security policy using the Lightsail console.

1. Sign in to the [Lightsail console](https://lightsail.aws.amazon.com/).

1. In the left navigation pane, choose **Networking**.

1. Choose the name of the load balancer for which you want to configure a TLS security policy.

1. Choose the **Inbound traffic** tab.

1. Choose **Change protocols** under the **TLS security protocols** section of the page.

1. Select one of the following options in the **Supported protocols** dropdown menu:
   + **TLS version 1.2** — This option is the most secure but older browsers might be unable to connect.
   + **TLS version 1.0, 1.1, and 1.2** — This option offers the most compatibility with browsers.

1. Choose **Save** to apply the selected protocol to your load balancer.

   Your change takes a few moments to become effective.

## Configure a security policy using the AWS CLI
<a name="configure-load-balancer-security-policy-cli"></a>

Complete the following procedure to configure a security policy using the AWS Command Line Interface (AWS CLI). You do this by using the `update-load-balancer-attribute` command. For more information, see [update-load-balancer-attribute](https://docs.aws.amazon.com/cli/latest/reference/lightsail/update-load-balancer-attribute.html) in the *AWS CLI Command Reference*.

**Note**  
You must install the AWS CLI and configure it for Lightsail before continuing with this procedure. For more information, see [Configure the AWS CLI to work with Lightsail](lightsail-how-to-set-up-and-configure-aws-cli.md).

1. Open a Command Prompt or Terminal window.

1. Enter the following command to change the TLS security policy for your load balancer.

   ```
   aws lightsail update-load-balancer-attribute --load-balancer-name LoadBalancerName --attribute-name TlsPolicyName --attribute-value AttributeValue
   ```

   In the command, replace the following example text with your own:
   + *LoadBalancerName* with the name of the load balancer for which you want to change the TLS security policy.
   + *AttributeValue* with the `TLS-2016-08` or `TLS-FS-1-2-Res-2019-08` security policy.
**Note**  
The `TlsPolicyName` attribute in the command specifies that you wish to edit the TLS security policy that is configured on the load balancer.

   Example:

   ```
   aws lightsail update-load-balancer-attribute --load-balancer-name MyLoadBalancer --attribute-name TlsPolicyName --attribute-value TLS-2016-08
   ```

   Your change takes a few moments to become effective.

# Redirect HTTP to HTTPS for Lightsail load balancers
<a name="amazon-lightsail-configure-load-balancer-https-redirection"></a>

After you configure HTTPS on your Amazon Lightsail load balancer, you can configure an HTTP to HTTPS redirect so that users who browse to your website or web application using an HTTP connection are automatically redirected to the encrypted HTTPS connection. For more information about load balancers, see [Load balancers](understanding-lightsail-load-balancers.md).

## Complete the prerequisites
<a name="configure-load-balancer-https-redirection-prerequisites"></a>

Complete the following prerequisites if you haven't already:
+ Create a load balancer and attach instances to it. For more information, see [Create a load balancer and attach instances to it](create-lightsail-load-balancer-and-attach-lightsail-instances.md).
+ Create an SSL/TLS certificate and attach it to your load balancer to enable HTTPS. For more information, see [Create an SSL/TLS certificate for your Lightsail load balancer](create-tls-ssl-certificate-and-attach-to-lightsail-load-balancer-https.md). For more information about certificates, see [SSL/TLS certificates](understanding-tls-ssl-certificates-in-lightsail-https.md).

## Configure HTTPS redirection on your load balancer using the Lightsail console
<a name="configure-load-balancer-https-redirection-console"></a>

Complete the following procedure to configure HTTPS redirection on your load balancer using the Lightsail console.

1. Sign in to the [Lightsail console](https://lightsail.aws.amazon.com/).

1. In the left navigation pane, choose **Networking**.

1. Choose the name of the load balancer for which you want to configure HTTPS redirection.

1. Choose the **Inbound traffic** tab.

1. In the **Protocols** section of the page, you can perform one of the following actions:  
![\[The toggle to activate or deactivate HTTP to HTTPS redirection on a load balancer\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/amazon-lighstail-load-balancer-redirection-toggle.png)
   + Toggle the direction option to active to turn on HTTP to HTTPS redirection.
   + Toggle the direction option to inactive to turn off HTTP to HTTPS redirection.

   Your change takes a few moments to become effective.

## Configure HTTP to HTTPS redirect for a load balancer with the AWS CLI
<a name="configure-load-balancer-https-redirection-cli"></a>

Complete the following procedure to configure HTTPS redirection on your load balancer using the AWS Command Line Interface (AWS CLI). You do this by using the `update-load-balancer-attribute` command. For more information, see [update-load-balancer-attribute](https://docs.aws.amazon.com/cli/latest/reference/lightsail/update-load-balancer-attribute.html) in the *AWS CLI Command Reference*.

**Note**  
You must install the AWS CLI and configure it for Lightsail before continuing with this procedure. For more information, see [Configure the AWS CLI to work with Lightsail](lightsail-how-to-set-up-and-configure-aws-cli.md).

1. Open a Command Prompt or Terminal window.

1. Enter the following command to configure HTTPS redirection on your load balancer.

   ```
   aws lightsail update-load-balancer-attribute --load-balancer-name LoadBalancerName --attribute-name HttpsRedirectionEnabled --attribute-value AttributeValue
   ```

   In the command, replace the following example text with your own:
   + *LoadBalancerName* with the name of the load balancer for which you want to activate or deactivate HTTP to HTTPS redirection.
   + *AttributeValue* with `true` to activate redirection, or `false` to deactivate redirection.
**Note**  
The `HttpsRedirectionEnabled` attribute in the command specifies that you wish to edit whether HTTPS redirection is enabled or disabled for the specified load balancer.

   Examples:
   + To activate HTTP to HTTPS redirection on your load balancer:

     ```
     aws lightsail update-load-balancer-attribute --load-balancer-name MyLoadBalancer --attribute-name HttpsRedirectionEnabled --attribute-value true
     ```
   + To deactivate HTTP to HTTPS redirection on your load balancer:

     ```
     aws lightsail update-load-balancer-attribute --load-balancer-name MyLoadBalancer --attribute-name HttpsRedirectionEnabled --attribute-value false
     ```

   Your change takes a few moments to become effective.

# Enable session persistence for Lightsail load balancers
<a name="enable-session-stickiness-persistence-or-change-cookie-duration"></a>

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
<a name="enable-session-persistence"></a>

1. In the left navigation pane, choose **Networking**.

1. Choose your load balancer to manage it.

1. Choose the **Inbound traffic** tab.

1. Choose **Enable session persistence**.  
![\[Session persistence enabled\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/session-persistence-enabled.png)

## Adjust the cookie duration
<a name="adjust-cookie-duration"></a>

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](lightsail-how-to-set-up-and-configure-aws-cli.md) 

1. Open a command prompt or a terminal window.

1. 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 259200
   ```

   In 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
           }
       ]
   }
   ```

# Configure health check settings for Lightsail load balancers
<a name="understanding-lightsail-load-balancer-health-checking"></a>

Health checking starts as soon as you attach your Lightsail instances to your load balancer, and it occurs every 30 seconds thereafter. You can see the health check status on the load balancer management page.

![\[Health check status indicator\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/target-instances-health-check-passed.png)


## Customize your health check path
<a name="why-customize-health-check-path"></a>

You might want to customize your health check path. For example, if your home page loads slowly or has a lot of images on it, you can configure Lightsail to check a different page that loads faster.

1. In the left navigation pane, choose **Networking**.

1. Choose your load balancer to manage it.

1. On the **Target instances** tab, choose **Customize health checking**.

1. Type a valid path for your health check, and then choose **Save**.  
![\[Customize the health check path\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/customize-health-checking-path.png)

## Health check metrics
<a name="health-check-metrics"></a>

The following metrics can help you diagnose health check problems. Use the AWS Command Line Interface or the Lightsail API to return information about the specific health check metric.
+ **`ClientTLSNegotiationErrorCount`** - The number of TLS connections initiated by the client that did not establish a session with the load balancer. Possible causes include a mismatch of ciphers or protocols.

  `Statistics`: The most useful statistic is `Sum`.
+ **`HealthyHostCount`** - The number of target instances that are considered healthy.

  `Statistics`: The most useful statistic are `Average`, `Minimum`, and `Maximum`.
+ **`UnhealthyHostCount`** - The number of target instances that are considered unhealthy.

  `Statistics`: The most useful statistic are `Average`, `Minimum`, and `Maximum`.
+ **`HTTPCode_LB_4XX_Count`** - The number of HTTP 4XX client error codes that originate from the load balancer. Client errors are generated when requests are malformed or incomplete. These requests have not been received by the target instance. This count does not include any response codes generated by the target instances.

  `Statistics`: The most useful statistic is `Sum`. Note that `Minimum`, `Maximum`, and `Average` all return `1`.
+ **`HTTPCode_LB_5XX_Count`** - The number of HTTP 5XX server error codes that originate from the load balancer. This count does not include any response codes generated by the target instances.

  `Statistics`: The most useful statistic is `Sum`. Note that `Minimum`, `Maximum`, and `Average` all return `1`. Note that `Minimum`, `Maximum`, and `Average` all return `1`.
+ **`HTTPCode_Instance_2XX_Count`** - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer.

  `Statistics`: The most useful statistic is `Sum`. Note that `Minimum`, `Maximum`, and `Average` all return `1`.
+ **`HTTPCode_Instance_3XX_Count`** - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. 

  `Statistics`: The most useful statistic is `Sum`. Note that `Minimum`, `Maximum`, and `Average` all return `1`.
+ **`HTTPCode_Instance_4XX_Count`** - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer.

  `Statistics`: The most useful statistic is `Sum`. Note that `Minimum`, `Maximum`, and `Average` all return `1`.
+ **`HTTPCode_Instance_5XX_Count`** - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer.

  `Statistics`: The most useful statistic is `Sum`. Note that `Minimum`, `Maximum`, and `Average` all return `1`.
+ **`InstanceResponseTime`** - The time elapsed, in seconds, after the request leaves the load balancer until a response from the target instance is received.

  `Statistics`: The most useful statistic is `Average`.
+ **`RejectedConnectionCount`** - The number of connections that were rejected because the load balancer had reached its maximum number of connections.

  `Statistics`: The most useful statistic is `Sum`.
+ **`RequestCount`** - The number of requests processed over IPv4. This count includes only the requests with a response generated by a target instance of the load balancer.

  `Statistics`: The most useful statistic is `Sum`. Note that `Minimum`, `Maximum`, and `Average` all return `1`.

**Topics**
+ [Customize your health check path](#why-customize-health-check-path)
+ [Health check metrics](#health-check-metrics)
+ [Health checks](enable-set-up-health-checking-for-lightsail-load-balancer-metrics.md)

# Configure Lightsail load balancer health checks
<a name="enable-set-up-health-checking-for-lightsail-load-balancer-metrics"></a>

By default, Lightsail performs health checks on your instances at the root (`"/"`) of your web application. The health checks are used to monitor the health of the registered instances so that the load balancer can send requests only to the healthy instances. The health checks start as soon as you attach the instances to your load balancer.

One of the following statuses is returned.
+ Passed
+ Failed

If your health check fails, you can try to figure out what is wrong by using the AWS Command Line Interface or the Lightsail API. See our troubleshooting guide for more information.

## Customize your health check path
<a name="customize-health-check-path"></a>

You might want to customize your health check path. For example, if your home page loads slowly or has a lot of images on it, you can configure Lightsail to check a different page that loads faster.

1. In the left navigation pane, choose **Networking**.

1. Choose your load balancer to manage it.

1. On the **Target instances** tab, choose **Customize health checking**.

1. Type a valid path for your health check, and then choose **Save**.  
![\[Customize the health check path\]](http://docs.aws.amazon.com/lightsail/latest/userguide/images/customize-health-checking-path.png)

# Detach instances from a Lightsail load balancer
<a name="detach-lightsail-instances-from-load-balancer"></a>

If you no longer want to have an instance attached to your Amazon Lightsail load balancer, you can detach it. When you detach a Lightsail instance from a load balancer, we wait until the specified instances are no longer needed before detaching.

1. In the left navigation pane, choose **Networking**.

1. Choose the load balancer you want to manage.

1. On the **Target instances** tab, choose **Detach** next to the load balancer you want to detach.

# Delete Lightsail load balancers
<a name="delete-lightsail-load-balancer"></a>

You can delete a Lightsail load balancer if you no longer need it. Deleting a load balancer also detaches any Lightsail instances attached to it but doesn't delete the Lightsail instances. If you enabled encrypted (HTTPS) traffic using an SSL/TLS certificate, deleting the load balancer will also permanently delete any SSL/TLS certificates associated with the load balancer.

**Important**  
Deleting a Lightsail load balancer and its associated certificate is final and can't be undone.

1. In the left navigation pane, choose **Networking**.

1. Choose the load balancer you want to delete.

1. Choose **Delete**.

1. Choose **Delete load balancer**.

1. Choose **Yes, delete**.