Application Load Balancer operates at the request level (layer 7), routing traffic to targets (EC2 instances, containers, IP addresses, and Lambda functions) based on the content of the request. Ideal for advanced load balancing of HTTP and HTTPS traffic, Application Load Balancer provides advanced request routing targeted at delivery of modern application architectures, including micro-services and container-based applications. Application Load Balancer simplifies and improves the security of your application, by ensuring that the latest SSL/TLS ciphers and protocols are used at all times.

In this post we going to create an Application Load Balancer.

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

Requirements

  • AWS Account

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 1 instance, select the sub-network 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. Repeat the process of launching a instance, but with a different sub-network.

14. After you add the second instance go to instances, select the first instance, copy the private IPv4 Address for later,  and click on Connect

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

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

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

17. 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.

18. Start the nginx server

systemctl start nginx

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

20. 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

21. Refresh and you will see the custom message

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

23. Select the second instance and click on Connect

24. 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.

25. Install nginx

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

26. 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.

27. Start the nginx server

systemctl start nginx

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

29. 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

30. Refresh the browser to see the second message

31. Go to EC2, Load Balancers

32. Click on Create Load Balancer

33. Click on Create in the part of Application Load balancer

34. Give it a name, select internet-facing, ipv4

35. In Availability Zones, select the zones the instances are, and click on Next

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

37. Create a new security group and add the 80 port and click on Next

38. In the next window, give it a name to the target group and click on Next, select IP as Target type

39. Add the instances private id's and add it to the list, then Click on Review

40. Review the configuration and click on Create

41. You will see the Creation status, if everything is OK, you will see a successful message, click on Close.

42. When the Application load balancer is active, select the Application, load balancer, and copy the DNS name

43. Test it on a web browser

44. Refresh the browser some times and you will see the two servers responding

Great, you have a Application load balancer working, in the next post we going deeper into the AWS Services.

Clean-Up

  1. On EC2, Load Balancers, select the load balancer and click Actions, Delete

2. Confirm

3. Go to Target groups, select the target group and click on Actions, Delete and confirm

4.  Go to Security groups and select the security groups we create with this lab and delete them, selecting them and on Actions clicking on Delete security group

5. Select the instances on EC2, and click on Instance state and click on Terminate instance and confirm