# #90daysofdevops #41 :Setting up an Application Load Balancer with AWS EC2  ☁

![LB2](https://user-images.githubusercontent.com/115981550/218145297-d55fe812-32b7-4242-a4f8-eb66312caa2c.png align="left")

## What is Load Balancing?

Load balancing is the distribution of workloads across multiple servers to ensure consistent and optimal resource utilization. It is an essential aspect of any large-scale and scalable computing system, as it helps you to improve the reliability and performance of your applications.

## Elastic Load Balancing:

**Elastic Load Balancing (ELB)** is a service provided by Amazon Web Services (AWS) that automatically distributes incoming traffic across multiple EC2 instances. ELB provides three types of load balancers:

Read more from [here](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html)

1. **Application Load Balancer (ALB)** - *operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.*
    

1. **Network Load Balancer (NLB)** - *operates at layer 4 of the OSI model and is ideal for applications that require high throughput and low latency.*
    

1. **Classic Load Balancer (CLB)** - *operates at layer 4 of the OSI model and is ideal for applications that require basic load balancing features.*
    

* ## 🎯 Today's Tasks:
    

### Task 1:

* launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.
    
* Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name also do it for 2nd instance which include " TrainWithShubham Community is Super Aweasome :) ".
    
* Copy the public IP address of your EC2 instances.
    
* Open a web browser and paste the public IP address into the address bar.
    
* You should see a webpage displaying information about your PHP installation.
    

### Task 2:

* Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
    
* Add EC2 instances which you launch in task-1 to the ALB as target groups.
    
* Verify that the ALB is working properly by checking the health status of the target instances and testing the load balancing capabilities.
    

> ***Launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.***

* Log in to your AWS Console and go to the EC2 dashboard. Click on the "Launch Instance" button and select "Ubuntu Server ".
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685168056262/79e38b6a-33eb-4a22-862c-9d91d5fddea5.png?auto=compress,format&format=webp align="left")
    
* Select the instance type and key pair based on your requirements and click "Next".
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685167970998/b4f0c589-9e25-4b4c-abab-c24bc60c1e20.png?auto=compress,format&format=webp align="left")
    
* Configure network settings.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685167989899/85bcb771-2810-4ef9-a870-5e6f2bd5e4fe.png?auto=compress,format&format=webp align="left")
    
* Add below script in user data of additional settings.
    
    **COPY**
    
    **COPY**
    
    ```plaintext
      #!/bin/bash
      sudo apt update
      sudo apt install -y apache2
      sudo systemctl start apache2
      sudo systemctl enable apache2
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685168015973/a874b58d-7465-4832-9dee-85fef4a3b7fb.png?auto=compress,format&format=webp align="left")
    
* 2 instances are running now.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685168222770/f4d8d278-d7e8-454c-af75-5a0d52453033.png?auto=compress,format&format=webp align="left")
    

> ***Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name also do it for 2nd instance which include " TrainWithShubham Community is Super Aweasome".***

**For Instance 1**

* Copy the public IP address of your EC2 instances.
    
* Open a web browser and paste the public IP address into the address bar.
    
* You should see a webpage displaying information about your PHP installation.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685168457051/46151739-7b79-40c3-972b-0993c6feae19.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685168692987/5cceb590-6b4d-4a7a-922f-1cb1982f77d6.png?auto=compress,format&format=webp align="left")
    
* Now change the index.html file.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685169051882/0c82ef3d-4645-4f0d-80fe-469ab3d60b5f.png?auto=compress,format&format=webp align="left")
    
* I have changed the text, see here.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685169034730/17f066a1-1110-46f1-902d-bfffce96bcf4.png?auto=compress,format&format=webp align="left")
    

**For Instance 2**

* Copy the public IP address of your EC2 instances.
    
* Open a web browser and paste the public IP address into the address bar.
    
* You should see a webpage displaying information about your PHP installation.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685168760212/0b06a038-8608-4966-b437-648c6e437f13.png?auto=compress,format&format=webp align="left")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685168784450/3ec0e3cd-8715-41f1-83fc-aefaf570060e.png?auto=compress,format&format=webp align="left")
    

* Now change the index.html file.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685169162751/8a1367d9-6260-48c1-a75a-00cfcb2a0d52.png?auto=compress,format&format=webp align="left")
    
* I have changed the text, see here.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685169251684/93f4c3e5-85b4-4d91-8365-34173a944a11.png?auto=compress,format&format=webp align="left")
    

---

### Task 2

> ***Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.***

* Navigate to "Load Balancers" in the EC2 dashboard.
    
* Click on the "Create Load Balancer" button.
    
* Select the "Application Load Balancer" type.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685169501473/e733b032-eeea-409f-bbb9-93f369fcc952.png?auto=compress,format&format=webp align="left")
    
* Provide a name for your load balancer.
    
* Select the appropriate scheme (internet-facing or internal) based on your requirements.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685169649818/70ea96d5-b7b6-4377-ae55-2029af137c7b.png?auto=compress,format&format=webp align="left")
    
* Choose the VPC where you want to create the load balancer.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685170643765/4135de61-535c-4bef-b473-9235f073f991.png?auto=compress,format&format=webp align="left")
    
* **<mark>Create Target groups</mark>**
    
* Select the instances that you want to register with the target group.
    
* These instances will receive traffic from the load balancer.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685171429206/1e35eed9-c7ec-42a6-89d0-bfb5b890d115.png?auto=compress,format&format=webp align="left")
    
    * Select the instances that you want to register with the target group.
        
    * These instances will receive traffic from the load balancer.
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685171467742/351fdd4c-b3e9-4913-915a-4a2a185580ef.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685170691284/7ae55546-4191-4fab-add6-0b2f875bf2a2.png?auto=compress,format&format=webp align="left")

* Choose an existing or create a new security group to control inbound traffic to your load balancer.
    
* Choose an existing or create a new target group.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685170667552/39f9523c-3992-4c48-b35d-1fd4c18ed3e3.png?auto=compress,format&format=webp align="left")
    
* Review the configuration settings and click on "Create" to create the ALB.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685170717675/a4b953aa-9c24-4f4a-9100-e33483eaf055.png?auto=compress,format&format=webp align="left")
    

> ***Add EC2 instances which you launch in task-1 to the ALB as target groups.***
> 
> ***Verify that the ALB is working properly by checking the health status of the target instances and testing the load balancing capabilities.***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685171380105/126c363f-cb43-4ae0-a6c3-eb3c182ce2c2.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685171304418/a6b9fcab-694e-47d0-ac14-15ab92c3320f.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685171314423/13ebb5c7-b983-4e88-9463-855c361c3e18.png?auto=compress,format&format=webp align="left")
