AWS EC2 ELB Hands-On | A Step-by-Step Guide

A step-by-step instructions on Elastic Load Balancing (ELB)

AWS EC2 ELB Hands-On | A Step-by-Step Guide

Launching multiple EC2 instances

To access full details about launching servers please follow AWS EC2 Hands-On | A Step-by-Step Guide

Step 1. Launching a New Instance

In the EC2 dashboard, click on the "Launch Instance" button

Step 2. Choose Name, AMI, and number of instances

Select an appropriate number of instances to share the load

Step 3. Update Key Pair (login), network settings and security group

  1. Let's proceed without Key-pair Login as we are not planning to SSH

  2. Select existing security group "launch wizard" which allowed us HTTP traffic and SSH traffic into our EC2

Step 4. Add User Data Script and Launch

  1. Go to Advance Settings and all the way to the bottom paste user Data.

COPY

#!/bin/bash

# Update the package repository and install Apache
yum update -y
yum install -y httpd

# Start the Apache service
service httpd start

# Enable Apache to start on system boot
systemctl enable httpd

# Create a simple HTML page to verify Apache installation
echo "<html><head><title>Test Page</title></head><body><h1>Apache is running! on host: $(hostname -f)</h1></body></html>" > /var/www/html/index.html
  1. Review Instance Launch: Review the configuration details of your instance.

  2. Click "Launch" to initiate the instance creation process.

Step 5: Access N copies of instance and rename

  1. Once your instance is launched, you can see the x number of copies of the instance running in your EC2 dashboard where monitor their status.

  2. In Below screenshot you can see that the Name is same but the Instance IDs are different

  1. Let's rename them by simply clicking on the pencil icon as we Hover

    1. Once satisfied click the tick to update and save

  2. You can now see the two different names

Step 6. Accessing and Managing Your Instance

  1. To access your instance, click on the "Instances" link in the navigation pane, then select your instance from the list.

  2. From here, you can view details about your instance, including its public IP address and status.

  3. To test the running instance go to http://<IP_address> or click of public IP above, just ensure it is http:// and not https://


Creating Security Group for Load Balancing

Step 1. Create a New Security Group

  1. In the EC2 dashboard, locate and click on "Security Groups" in the left-hand sidebar under the "Network & Security" section.

  2. Click on the "Create Security Group" button.

  3. Provide a name and description for your security group.

  4. Define inbound and outbound rules based on your requirements. You can specify protocols, ports, and IP ranges for both inbound and outbound traffic.

  5. Click on the "Create" button to create your new security group.


Create Target Groups

Step 1. Create target group**

  1. Log in to the AWS Management Console and navigate to the EC2 dashboard.

  2. Under the "Load Balancing" section in the navigation pane, click on "Target Groups."

  3. Click the "Create target group" button.

Step 2. Basic configuration

Settings in this section can't be changed after the target group is created.

  1. Choose Target Types:

    • Instances: Balances load within a VPC, works with EC2 Auto Scaling.

    • IP addresses: Balances load to VPC and on-premises resources, supports multiple IPs and interfaces, ideal for microservices and IPv6.

    • Lambda function: Routes to a single Lambda function, exclusive to Application Load Balancers.

    • Application Load Balancer: Handles TCP requests within a VPC, supports static IPs and PrivateLink.

As seen for EC2 Auto scaling we will choose "Instances"

  1. Specify a name and optional description for the target group.

  2. Choose the protocol and port for the target group, aligning with your application's settings.

Step 3: Configure health checks

  1. Configure health checks to monitor target health, including protocol, port, and interval.

  2. 2. Click on "Next"

Step 4: Register targets

  1. Set targets by registering instances manually or using an AWS Auto Scaling group.

  2. Review the configuration and click "Create target group" to finalize.

  3. After creation, associate the target group with a load balancer or adjust settings as needed for your application architecture.


Create a Load Balancer (ALB)

Step 1: Create Load Balancer

  1. Navigate to the EC2 dashboard

  2. Click on "Load Balancers" in the navigation pane.

  3. Click on "Create Load Balancer"

Step 2: Choose Load Balancer Type

  1. You can choose the type of load balancer you want to create (Classic Load Balancer, Application Load Balancer, Network Load Balancer, Gateway Load Balancer).

  2. You can learn the details about Types of load balance in AWS ELB Elastic Load Balancing Type

Step 3: Basic configuration

Add Load balancer name, Scheme and IP address type

Step 4: Configure Network mapping

The load balancer routes traffic to targets in the selected subnets, and in accordance with your IP address settings.

Select at least two Availability Zones and one subnet per zone.

Step 5: Add Security groups

Step 6: Listeners and routing
A listener is a process that checks for connection requests using the port and protocol you configure. The rules that you define for a listener determine how the load balancer routes requests to its registered targets.

  1. Add EC2 instances or target groups to the load balancer.

Step 7: Review and create the load balancer.


Testing and Monitoring

    1. Go to the "Load Balancers" section in the EC2 dashboard.

      1. Locate the load balancer associated with your Auto Scaling Group.

      2. Click on the load balancer to view its details.

      3. Copy the DNS name of the load balancer from the dashboard.

      4. Paste the DNS name into a text editor or another location for future reference or testing purposes.

      5. Optionally, you can open a web browser and paste the DNS name into the address bar to access your application through the load balancer.

      6. Add load by refreshing to see the load being distributed to Different IP