AWS Elastic Load Balancer
Published: 2023-11-27 14:39:56

We are going to see how to create a Elastic Load Balancer(ELB)

Step 1. we need to create and launch the instance with Ubuntu OS and with instance type as t2.nano and selected the existing key pair and security group and set 2 instance to create and launch.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m7fyf4s8f7tjedara82r.png)

Step 2. Edit the name as app_server-1 and app_server-2 for identification.
login via ssh using the public IP of each instance and do the "sudo apt update","sudo spt install apache2 -y" remove the index.html file and create and edit new index.html file.
Enable & verify the status of the service using "sudo systemctl enable apache2", "sudo systemctl status apache2".
verify the apache application by running "curl @(pubilc IP of EC2-Instance)"

```
kannan@kannan-PC:~$ ssh -i apache.pem ubuntu@13.234.122.186

ubuntu@ip-172-31-35-171:~$ sudo apt update

ubuntu@ip-172-31-35-171:~$ sudo apt install apache2 -y

ubuntu@ip-172-31-35-171:~$ sudo rm /var/www/html/index.html 
ubuntu@ip-172-31-35-171:~$ sudo vi /var/www/html/index.html 

ubuntu@ip-172-31-35-171:~$ sudo systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2
ubuntu@ip-172-31-35-171:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-11-27 13:37:55 UTC; 1min 37s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 2249 (apache2)
      Tasks: 55 (limit: 517)
     Memory: 6.4M
        CPU: 39ms
     CGroup: /system.slice/apache2.service
             ├─2249 /usr/sbin/apache2 -k start
             ├─2251 /usr/sbin/apache2 -k start
             └─2252 /usr/sbin/apache2 -k start

Nov 27 13:37:55 ip-172-31-35-171 systemd[1]: Starting The Apache HTTP Server...
Nov 27 13:37:55 ip-172-31-35-171 systemd[1]: Started The Apache HTTP Server.

ubuntu@ip-172-31-35-171:~$ curl @13.234.122.186
<h1>Application running on server-1</h2>


```

Step 3.Follow the above same procedure for the second instance and verify.

```
ubuntu@ip-172-31-34-163:~$ sudo rm /var/www/html/index.html 
ubuntu@ip-172-31-34-163:~$ sudo vi /var/www/html/index.html 
ubuntu@ip-172-31-34-163:~$ curl @13.109.139.153
<h1>Application running on server-2</h1>

```
 Now 2 apache application is running on the two instance.

Step 4. Create a Target group

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvdiuc6oup4r36clx0bu.png)

Step 5. Create a Load Balancer

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlu3ngivn2dagqvndbip.png)

Step 6.Select and create Application load balancer type.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tv9fjqs14dziba0x5940.png)

Step 7.Set the basic configuration 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5d1cq7vd47pdeiy308uu.png) 

Step 8. Set Network mapping

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/psnwy4e1a9qbbvmjvryr.png)

Step 9. Set security group and select the target groups which we have created.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhbr7871s6zfpbbgreaw.png)

Step 10. On the summary tab we need to verify the settings and create the load balancer. it took approx 5 mins for provisioning.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m0pf4xu8bfebsz5a7g28.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/py9pn9lpaa2o20njo13m.png)

Step 11. Once the ELB has been active open and copy the DNS and verify on the browser for every refresh it will change the instance using ELB.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sijyg31b4wc3wnttalkd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4g8qxtmdzhcdzyf4n8sy.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ozgls2ojk02j8xqsqi29.png)