AWS Classic Load Balancer is part of the Elastic Load Balancing services provided by AWS.

Elastic Load Balancing automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, IP addresses, Lambda functions, and virtual appliances. It can handle the varying load of your application traffic in a single Availability Zone or across multiple Availability Zones. Elastic Load Balancing offers four types of load balancers that all feature the high availability, automatic scaling, and robust security necessary to make your applications fault tolerant.

In this post we going to learn how to make a Classic Load Balancer and see how it works.

Requirements

  • AWS Account

Steps:

  • Launch two EC2 instances
  • Connect each instance and install nginx and a custom message for each server.
  • Create a Classic Load Balancer and configure the instances
  • Test the Classic Load Balancer

Hands-On

  1. In the AWS Management Console go to EC2

2. Go to instances

3. Click on Launch instances

4. Select Amazon Linux 2 AMI - 64 bits

5. Select t2.micro and click on Next

6. In the next window make sure you have the Auto-assign Public IP enabled, select 2 instances,  leave everything else on defaults and click Next

7. In the Add Storage step you can leave it as default, and click on Next

8. In Add tags, leave as default and click Next

9. In the next window, create a new security group and give it a name, you will have as default the port 22 open to connect via ssh, click on Add Rule and add the port 80 for the nginx server (type HTTP), and click Review and Launch

10. Review the information and click on Launch

11. In the next window, select Create a new key pair, give it a name, download and click on Launch instances

12. You will see the Launch status, if everything is correct, you will have a confirmation, click on View Instances

13. In the instances, select the first instance and click on Connect

14. On the EC2 Instance Connect, copy the IP address for later and click on Connect

15. This will open a new window with an emulated terminal in the instance, now install nginx

sudo su -
amazon-linux-extras install -y nginx1

16. Check the status of nginx

systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: di
sabled)
   Active: inactive (dead)

Dec 14 21:04:22 ip-172-31-29-155.us-east-2.compute.internal systemd[1]: Unit nginx...
Hint: Some lines were ellipsized, use -l to show in full.

17. Start the nginx server

systemctl start nginx

18. Open in a new browser tab the public IP to check is working

19. Now lets customize the landing page, then use exit to close the connection, and close the tab or window.

echo "This is the first server" > /usr/share/nginx/html/index.html
exit
exit

20. Refresh and you will see the custom message

21. Repeat the steps with the second instance, click on instances

22. Select the second instance and click on Connect

23. On the EC2 Instance Connect tab, copy the public IP address for later, click on Connect, this will open a emulated terminal on a new browser window.

24. Install nginx

sudo su -
amazon-linux-extras install -y nginx1

25. Check the status of the nginx server

systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: di
sabled)
   Active: inactive (dead)

Dec 14 21:21:11 ip-172-31-24-113.us-east-2.compute.internal systemd[1]: Unit nginx...
Hint: Some lines were ellipsized, use -l to show in full.

26. Start the nginx server

systemctl start nginx

27. Open a new tab o browser window and open the public IP address to check the nginx installation

28. Now lets customize the message in the second server, and use exit close the connection.

echo "This is the second server" > /usr/share/nginx/html/index.html
exit
exit

29. Refresh the browser to see the second message

30. Go to EC2, Load Balancers

31. Click on Create Load Balancer

32. On the Classic Load Balancer click on Create

33. In the next window, give it a name, and click on Next

34. Give it a name and click on Next

35. In the next window, select create a new security group with the port 80 open and click on next

36. In the window you can ignore the warning and click next

37. In the health check we can leve it as default and click Next

38. Add the two instances, and click Next

39. Click on Review and Create

40. In the next window, review the configuration and click on Create

41. You will see the Creation status, if everything is correct, click on close.

42. In the Load balancer window, select the load balancer and copy the DNS name to test

43. Open the DNS name in the browser and refresh some times, you will see that the two servers are responding.

Great, the Classic load balancer is working, in further post we going to go deeper in the AWS Services.

Clean-Up

  1. In EC2, Load Balancers, Select the load balancer, click on Actions, and click on Delete

2. Confirm

3. In EC2, instances, select the two instances, click on Instance state, and click on Terminate instance

4. Confirm

5. On EC2, Security groups, select the security groups we create on this lab, and click on Delete security group

6. Confirm

7. On EC2, Click on Key Pairs, select the key pair, and click on Actions, select Delete

8. Delete