AWS multi-AZ load balancer setup over HTTP

Rayan Khalil Sebbar
5 min readFeb 24, 2024

--

This article to describe how to setup an Application Load Balancer (ALB) on AWS. The following schema is what you can achieve here:

Diagram realized on draw.io

Note that all the steps performed below are included in AWS Free tier offering. You can find more details on aws.amazon.com/free/.

📝 Requirements

  • AWS account

⭐Step 1 — Create security groups

Firstly, we are going to create our two security groups to control inbound and outbound traffic to our ALB and EC2 instances.

Go to AWS EC2 > Security Groups > Create Security Group

A) Security group for our ALB

  • Give a name, a description and choose your VPC (I’m using the default one)
  • Add an inbound rule:
    ​ ​ ​​​ ​ ​​​ ​ ​​​Type: HTTP​​​ ​/ ​​​Source: Anywhere-IPv4
  • Add an outbund rule:
    ​ ​ ​​​ ​ ​​​ ​ ​​​Type: HTTP​​​ ​/ ​​​Destination: Put here your VPC CIDR

B) Security group for our EC2 instances

  • Give a name, a description and choose your VPC (I’m using the default one)
  • Add an inbound rule:
    ​ ​ ​​​ ​ ​​​ ​ ​​​Type: HTTP​​​ ​/ ​​​Source: {Select your ALB security group}
  • Add an outbund rule:
    ​ ​ ​​​ ​ ​​​ ​ ​​​Type: HTTP​​​ ​/ ​​​Destination: {Select your ALB security group}

⭐Step 2— Create web server instances per AZ

A) Create instance from a first Availability zone (AZ)

Go to EC2 > Launch instance. Give a name to your instance:

Leave by default OS (Free tier):

Leave by default instance type (Free tier) and select ‘Proceed without a key pair’:

Select your previously created security group for your EC2 instance then choose your subnet in your desired availability zone:

Finally, copy paste ‘User data’ section following bash script to install Apache web server on your instance and render ‘Hello from first AZ instance’ as HTML.

B) Create instance from a second availability zone (AZ)

Repeat same steps as for the first instance but choose another Availability Zone when selecting the subnet.

Copy paste modified user data to render ‘Hello from second AZ instance’:

⭐Step 2— Start Load Balancer creation

Go to EC2 > Load balancers. Click on ‘Create load balancer’

Choose ‘Application Load Balancer’ by clicking on ‘Create’:

Select ‘Internet-facing’ and ‘IPv4’:

Select the VPC you used before for your EC2 instances and Security groups then select both availability zone where you created EC2 isntances:

Select ALB security group you created in first section of this article:

⭐Step 3— Listener and target group setup

Click on ‘Create target group’, you should be redirected in another tab:

On Step 1, leave every field by default.

On Step 2, you should see your previously created instances. Select them and click on ‘Include as pending below’:

Then click on ‘Register pending targets’:

You can then come back to the Load Balancer Creation page to refresh and select the target group list:

⭐Step 4— Let’s check our setup

You can finally leave other settings as default and click on ‘Create Load Balancer’; wait until status switched from ‘Provisioning’ to ‘Active’:

Once status is ‘Active’, you can copy paste your ALB DNS name and paste it in another tab on your browser with “http://” prefix

You should get a response from one of the AZ web server:

When refreshing the web page we randomly get the other one (as we did not configured load balancing routing rules):

Thanks for reading! Please share and recommend to other interested readers!

Don’t hesitate to reach out if you have any questions around this!

--

--