This lab walks you through AWS Elastic Load Balancing. Elastic Load Balancing automatically distributes incoming application traffic across multiple Amazon EC2 instances in the cloud. In this lab, we will demonstrate elastic load balancing with 2 EC2 Instances using Terraform.
Duration: 1 hour
AWS Region: US East (N. Virginia) us-east-1
ELB is a service that automatically distributes incoming application traffic and scales resources to meet traffic demands.
ELB helps in adjusting capacity according to incoming application and network traffic.
ELB can be enabled within a single availability zone or across multiple availability zones to maintain consistent application performance.
ELB offers features like:
Detection of unhealthy EC2 instances.
Spreading EC2 instances across healthy channels only.
Centralized management of SSL certificates.
Optional public key authentication.
Support for both IPv4 and IPv6.
ELB accepts incoming traffic from clients and routes requests to its registered targets.
When an unhealthy target or instance is detected, ELB stops routing traffic to it and resumes only when the instance is healthy again.
ELB monitors the health of its registered targets and ensures that the traffic is routed only to healthy instances.
ELB's are configured to accept incoming traffic by specifying one or more listeners. A listener is a process that checks for connection requests.
Listeners are configured with a protocol and port number from the client to the ELB and vice-versa i.e., back from ELB to the client.
ELB supports 3 types of load balancers:
Application Load Balancers
Network Load Balancers
Classic Load Balancers
Each load balancer is configured differently.
For Application and Network Load Balancers, you register targets in target groups and route traffic to target groups.
For Classic Load Balancers, you register instances with the load balancer.
AWS recommends users to work with Application Load Balancer to use multiple Availability Zones because if one availability zone fails, the load balancer can continue to route traffic to the next available one.
We can have our load balancer be either internal or internet-facing.
The nodes of an internet-facing load balancer have Public IP addresses, and the DNS name is publicly resolvable to the Public IP addresses of the nodes.
Due to the point above, internet-facing load balancers can route requests from clients over the Internet.
The nodes of an internal load balancer have only Private IP addresses, and the DNS name is publicly resolvable to the Private IP addresses of the nodes.
Due to the point above, internal load balancers can only route requests from clients with access to the VPC for the load balancer.
Both internet-facing and internal load balancers route requests to your targets using Private IP addresses.
Your targets do not need Public IP addresses to receive requests from an internal or an internet-facing load balancer.
It is an open-source IaaC (Infrastructure as a Code) software tool where you define and create resources using providers in the declarative configuration language example JSON.
With Terraform, You can package and reuse the code in the form of modules.
It supports a number of cloud infrastructure providers such as AWS, Azure, GCP, IBM Cloud, OCI, etc.
Terraform has four major commands:
Install Terraform in your local machine using this official guide by Hashicorp.
To install Terraform using CLI, use this guide https://learn.hashicorp.com/tutorials/terraform/install-cli
To install Terraform by downloading, use this guide https://www.terraform.io/downloads.html
Download and Install Visual Studio code editor using this guide https://code.visualstudio.com/download
Setup Visual Studio Code.
Create a Variables file.
Create EC2, ELB and its components in main.tf file
Create an Output file.
Confirm the installation of Terraform by checking the version.
Apply Terraform configurations.
Check the HTML page and traffic distribution.
Check the resources in AWS Console.
Validation of the lab.
Deleting AWS Resources.