DEV Community

Cover image for Add Lightsail Load Balancer to Application hosted in Amazon Lightsail instance(s)
Harun R Rayhan for AWS Community Builders

Posted on • Originally published at blog.harun.dev

Add Lightsail Load Balancer to Application hosted in Amazon Lightsail instance(s)

Lightsail offers Load Balancer. It's very easy to provision one and attach one or multiple instances to it. Let's create one and attach instances to it.

Prerequisites

You need one or more Amazon Lightsail instances to attach to the load balancer in the same region. You can create it by following Deploy Laravel Application to Amazon Lightsail or Deploy WordPress App to Amazon Lightsail

⚠ī¸ Warning: Amazon Light Load Balancer going to cost you USD$18/month. It has no pre-tier available. Be sure before going to provision one. You can check the whole article before creating.

Provision a Load Balanced

  1. Go to the homepage of the Amazon Lightsail console. Click on the Networking tab and click on the Create load balancer button.
    CleanShot 2022-05-28 at 16.02.40@2x.png

  2. You are in the Create a Load balancer screen like this 👇
    CleanShot 2022-05-28 at 16.04.46@2x.png

    • A. Change your region to where your instances are. My instances are in Virginia.
    • B. Give it a name, and
    • C. Hit the Create load balancer button from the bottom.
  3. Load balancer will be created in a moment and you should land on the Load balancer page.

Attach instances to the Load balance

  1. Go to the homepage again and then click the Networking tab. You should see Loadbalancer(s) including the one just created. Click on the name of the Load balancer.
    CleanShot 2022-05-28 at 16.13.01@2x.png

  2. Our load balancer doesn't have any attached instance(s) yet, we are going to attach one or more. Select your instance in the Target instances section.
    CleanShot 2022-05-28 at 16.15.02@2x.png
    I just have one in this region. You should see all of the instances you have in the region where the load balancer is provisioned.

  3. Confirm the attachment of your instance
    CleanShot 2022-05-28 at 16.19.15@2x.png

  4. Do the same process until you attached all of your target instances.

  5. Go to Load balancer URL (DNS name) and you should see your application.
    CleanShot 2022-05-28 at 16.26.00@2x.png

ℹī¸ If you don't see the desired page, check your application or other tools (Apache, Nginx, etc.) setting.

Add Domain or Sub-Domain

  1. You can create DNS Zone in Lightsail for your domain and configure it. Follow this to add your domain/sub-domain.

  2. You can add the Load balancer URL (DNS name) as A record in your domain's DNS control panel.

Enable HTTPS

  1. Go to the Inbound traffic tab of your Load balancer setting. CleanShot 2022-05-28 at 16.35.34@2x.png
    • A. Create an SSL certificate for your domain by clicking the Create certificate + button.
    • B. You should see all of the created certificates in the SSL/TLS certificate list and select the one you just created.
    • C. Optionally, you can Redirect from HTTP to HTTPS. (After enabling the HTTPS).

Conclusion

Hope you enjoyed this short article. You can subscribe to my newsletter, and follow me on Twitter, Dev.to, and Hashnode.

Top comments (0)