AWS Load Balancer: EC2 Integration, Target Groups & CCP Exam

suyodhanj6 Last Updated : 30 Jan, 2024
9 min read

Introduction


In the cloud industry, various providers like AWS, GCP, and Azure offer a range of services. Currently, AWS stands out as the most popular, with one of its key services being the AWS Load Balancer. This service efficiently manages traffic across different regions. By leveraging this service, for instance, when hosting a website facing a surge in user traffic, we can effectively handle and distribute the load. It’s common to observe that, without load balancing, some websites’ servers may experience downtime during peak times. However, implementing a load balancer enables us to regulate and distribute traffic across various regions, mitigating the risk of server shutdowns.

In AWS, different types of load balancers exist, including the Classic Load Balancer, Application Load Balancer, and Network Load Balancer. Each type offers unique features, use cases, and benefits, and the choice depends on our specific use case.

In this blog, our motive is to explore the theory of load balancing with practical examples, considering sub-components like EC2 instances and Target Groups. The primary focus is to prepare for the CCP exam.

"

Learning Objective

  • Learn about load balancers and their types, including features and differences between them.
  • Understand the step-by-step process of creating a load balancer with EC2 instances.
  • Explore target groups and learn how to create them for different regions.
  • Additionally, discover 10 questions for the CCP exam.

This article was published as a part of the Data Science Blogathon.

What is a Load Balancer?

What is a Load Balancer?

A load balancer is a service provided by AWS that handles incoming network traffic or application requests across different servers or resources. In simpler terms, when multiple people request a website simultaneously, the goal is to avoid overwhelming a single server. That’s why the load balancer enhances the performance, availability, and reliability of the system.

Simple Workflow: 

User/Server Request
    |
    v
Load Balancing Algorithm (e.g., Round Robin)
    |
    v
Available Server Selection
    |
    v
Processing and Forwarding Request to Selected Server
    |
    v
Server Response
    |
    v
User/Client

Benefits:

  • Scalability:
    • A Load Balancer divides the traffic among different servers, allowing them to easily handle the load.
  • High Availability:
    • By distributing the traffic among several servers, reliability increases. If one server is not responding, the workload shifts to a different server.
  • Improved Performance:
    • User experience is faster and more seamless. Consequently, performance automatically increases.
  • Fault Tolerance:
    • Load balancers monitor the health of servers through health checks. If a server becomes unhealthy, the load balancer automatically redirects traffic to healthy servers, enhancing fault tolerance.

Also Read: What is AWS? Why Every Data Science Professional Should Learn Amazon Web Services

Difference Between the Types of Load Balancers

Feature Classic Load Balancer (CLB) Application Load Balancer (ALB) Network Load Balancer (NLB)
Layer 4 (TCP/UDP) Load Balancing Yes No Yes
Layer 7 (HTTP/HTTPS) Load Balancing Yes (Limited compared to ALB) Yes No
WebSockets Support No Yes Yes
SSL/TLS Termination Yes (Limited compared to ALB) Yes Yes
Path-Based Routing No Yes No
Host-Based Routing No Yes No
Containerized Application Support No Yes No
Static IP for Load Balancer Yes No Yes
Health Checks Yes Yes Yes
Integration with AWS WAF No Yes No
IPv6 Support Yes Yes Yes
Billing Fixed per hour Pay-as-you-go Pay-as-you-go

Prerequisites

  1. AWS EC2 Instances🚀 :
    • We want to create one or more EC2 instances. In the following steps, we will create two instances in the same region.
  2. Security Groups🔒:
    • We want to create inbound and outbound rules for the EC2 instances.
    • We want to create target groups to handle different types of traffic.

Creating Step-By-Step AWS EC2 Instance(First)

  • Step 1: Login to the AWS Console. check the login or sign-up procedure.
  • Step 2:  Go to the EC2 Machine search the EC2 option click the first link & Launch the Machine.
Creating Step-By-Step AWS EC2 Instance(First)
  • Step 3:  Give the name for the EC2 Machine(instance1) and choose the Amazon machine.
  • Step 4:  For learning, Purpose Check the Free version. check the red square here for the information related to the RAM, and SSD By choosing the best for our requirements the cost might be reduced. so choose according to your requirements. other bill might be high.
Creating Step-By-Step AWS EC2 Instance(First)
  • Step 5:  Create a Key Pair. so we can use it in the next EC2 machine.
  • Step 6: Remember the name we assigned to the security group and verify the checklist of rules. allow all types of traffic. click the three options.
Creating Step-By-Step AWS EC2 Instance(First)
  • Step 7:  Check if the instance number is 1. While we can create 2 instances at this time, we prefer to create two instances with different IDs for a better understanding. the option is on the right side (like 1)
  • Step 8:  Launch the EC2 Machine. the option is available on the bottom right side.
  • Step 9:  Select the machine on the top side connect option is available then  Connect to the EC2 machine(instance2).
  • Step 10: After that, write the following command to switch to the root user, create the ‘script.sh’ (for automated processes), and change the permissions.
sudo su

touch script.sh

chmod +x script.sh

nano script.sh

## Past this code after running the above command
#!/bin/bash
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo "Hello Prashant from $(hostname -f)" > /var/www/html/index.html
  • Step 11:  On the bottom side there is an address present Copy the address and paste the browser to check the result.

Creating Step-By-Step AWS EC2 Instance(Second)

We are creating a second machine to better understand how the workload is divided. At this step, check the security groups. Here, we don’t want to create new security groups but make sure to select the previously selected security group.

  • Step 1:  Give the name for the EC2 Machine(instance2) same as in the above steps.
  • Step 2:  For learning, Purpose Check the Free version. so we can minimise the cost of EC2.
  • Step 3:  This step is imp, check the previously created key pair (name). like we create load_bal. In the below image we can see the key pair name that we previously created.
Creating Step-By-Step AWS EC2 Instance(Second)
  • Step 4:  In this step, check the security group’s name. In the previous, we saw the What is our security group name the name is important.
Creating Step-By-Step AWS EC2 Instance(Second)
  • Step 5:  Launch the EC2 Machine. the option is available on the bottom of the right side.
  • Step 5:  Connect to the EC2 machine(instance2). the option is available in the top middle.
  • Step 6: After that, write the following command to switch to the root user, create the ‘script.sh’ (for automated processes), and change the permissions
sudo su

touch script.sh

chmod +x script.sh

nano script.sh

## Past this code after running the above command
#!/bin/bash
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo "Hello Sushant from $(hostname -f)" > /var/www/html/index.html
  • Step 5: On the bottom side there is an address present Copy the address and paste the browser to check the result.

Creating Target Groups

We want target groups to facilitate the distribution of incoming traffic among different instances. Essentially, we created two instance machines above and after integrating into the load balancer. The target groups divide incoming requests among the instances. It’s important in load balancing to route the traffic effectively.

Why do we need it?

  • Traffic Distribution and Scalability
  • Health Checks and Path-Based Routing (in ALB)
  • Ease of Management and Integration with Auto Scaling

Now, let’s look at the steps to create target groups!

  • Step 1: On the left down, click the target groups option or you can search the target groups and click the first link.
  • Step 2:  Select the instance option. check other options also as your requirements do select.
Creating Target Groups
  • Step 3:  Give the name of the target group. that name reflects the main UI of the target group.
  • Step 4: Select the available instances based on your demand. I want to, so I select the two instances.
Creating Target Groups
  • Step 5: Create the target group. by selecting the create option we can create the target groups.
  • Step 6: After creating the target group check the UI. so the target groups are available or not.

Build the Load Balancer

When you build a load balancer, you’re taking a crucial step in setting up a web application or service that can grow, stay reliable, and perform well. Think of a load balancer like a traffic manager – it spreads out incoming requests among several servers or instances. This helps make sure resources are used efficiently and no single server gets too much traffic, which could slow it down

  • Step 1: First search the load balancer and open In the top right, click the ‘Create Load Balancer’ option.
  • Step 2: After that, select the ‘Application Load Balancer’ and create it. check the other option also as i mentioned in the starting we can see the difference between this service.
Build the Load Balancer
  • Step 3: After creating the load balancer, check its state. Make sure it is ‘Active’; if not, wait a little bit of time.
  • Step 4: After that, copy the DNS address from the bottom right. after copying the address and pressing in browse we see the output.
Build the Load Balancer
  • Step 5: Check the result(1). this result represents the instance1 machine.
  • Step 6: Check the result(2) For sample purposes check the below image. this result represents the instanc21 machine
Build the Load Balancer

MCQ AWS Certified Cloud Practitioner (CCP)

Q1: What is the primary purpose of an AWS Load Balancer?

A. Distributing emails across instances

B. Managing database replication

C. Distributing incoming application traffic

D. Allocating storage to instances

Answer: C. Distributing incoming application traffic

Q2: Which AWS Load Balancer type is best suited for handling HTTP/HTTPS traffic and provides content-based routing?

A. Classic Load Balancer

B. Application Load Balancer (ALB)

C. Network Load Balancer (NLB)

D. Elastic Load Balancer (ELB)

Answer: B. Application Load Balancer (ALB)

Q3: What is the benefit of using Target Groups with an AWS Load Balancer?

A. Improved database performance

B. Dynamic scaling of EC2 instances

C. Enhanced security group configurations

D. Faster data transfer between instances

Answer: B. Dynamic scaling of EC2 instances

Q4: In the context of AWS Load Balancer, what is a listener?

A. A person managing the load balancer

B. A process monitoring target instances

C. A protocol and port combination for routing traffic

D. A health check configuration for instances

Answer: C. A protocol and port combination for routing traffic

Q5: Which AWS Load Balancer type is suitable for distributing TCP/UDP traffic?

A. Classic Load Balancer

B. Application Load Balancer (ALB)

C. Network Load Balancer (NLB)

D. Elastic Load Balancer (ELB)

Answer: C. Network Load Balancer (NLB)

Q6: What is the primary function of a health check in AWS Load Balancer?

A. Evaluating the financial health of instances

B. Assessing the availability of target instances

C. Checking the security configurations of instances

D. Monitoring the network latency between instances

Answer: B. Assessing the availability of target instances

Q7: Which AWS service is commonly used to monitor the performance of AWS Load Balancer?

A. Amazon RDS

B. Amazon S3

C. AWS CloudWatch

D. AWS Lambda

Answer: C. AWS CloudWatch

A. Open all inbound ports for flexibility

B. Restrict inbound traffic based on the principle of least privilege

C. Share private key pairs between instances

D. Use the default IAM role for all instances

Answer: B. Restrict inbound traffic based on the principle of least privilege

Q9: Which AWS Load Balancer type can handle both IPv4 and IPv6 traffic?

A. Classic Load Balancer

B. Application Load Balancer (ALB)

C. Network Load Balancer (NLB)

D. Elastic Load Balancer (ELB)

Answer: C. Network Load Balancer (NLB)

Q10: What is the significance of an Availability Zone (AZ) in the context of AWS Load Balancer?

A. It represents the time a load balancer is available for use.

B. It is a geographic location where AWS data centers are clustered.

C. It determines the number of target groups associated with a load balancer.

D. It is a parameter used for calculating load balancer costs.

Answer: B. It is a geographic location where AWS data centers are clustered.

Conclusion

In conclusion, understanding the integration of AWS Load Balancers with EC2 instances, the significance of Target Groups, and insights into CCP exam topics is crucial for optimizing performance and reliability in cloud environments. Effectively configuring load balancers, utilizing target groups, and being well-prepared for exam-related concepts empower users to harness the full potential of AWS services while ensuring smooth and scalable application delivery. This knowledge enhances both the practical implementation of load-balancing solutions and success in AWS Certified Cloud Practitioner (CCP) examinations.

Key Takeaways

  • AWS Load Balancers efficiently handle incoming traffic from users and servers.
  • Creating target groups enables the seamless integration of EC2 machines with the load balancer.
  • Preparing for the AWS Certified Cloud Practitioner (CCP) exam and successfully completing practical implementations go hand in hand.
  • The load balancer helps us provide reliability and availability, ensuring users have a seamless experience.

Resources for Further Learning

  • AWS Documentation of Load Balancer: Link
  • AWS Exam UI: Link

The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

As a Data Scientist, I leverage my expertise in statistical analysis, machine learning, and data visualization to derive insights and make informed decisions. I have experience working with various programming languages, databases, and machine learning frameworks, enabling me to tackle complex data problems and deliver actionable results. I am a collaborative problem-solver who can work with stakeholders to deliver scalable and secure data solutions.

Responses From Readers

Congratulations, You Did It!
Well Done on Completing Your Learning Journey. Stay curious and keep exploring!

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details