0
0
AWScloud~30 mins

Network Load Balancer (NLB) in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a Network Load Balancer (NLB) with AWS CDK
📖 Scenario: You are setting up a simple Network Load Balancer (NLB) in AWS to distribute incoming TCP traffic to backend servers. This is a common task when you want to improve availability and scalability of your application.
🎯 Goal: Build an AWS CDK stack that creates a Network Load Balancer with one listener on port 80 and a target group with two IP targets.
📋 What You'll Learn
Create a Network Load Balancer named myNLB in the default VPC
Add a listener on port 80 for TCP protocol
Create a target group named myTargetGroup with TCP protocol on port 80
Add two IP targets with IP addresses 10.0.0.10 and 10.0.0.11 to the target group
💡 Why This Matters
🌍 Real World
Network Load Balancers are used to distribute TCP traffic efficiently to backend servers, improving availability and scalability of applications.
💼 Career
Understanding how to configure NLBs with AWS CDK is important for cloud engineers and developers managing scalable network architectures.
Progress0 / 4 steps
1
Create the Network Load Balancer
Create a Network Load Balancer called myNLB in the default VPC using AWS CDK. Use the NetworkLoadBalancer construct from @aws-cdk/aws-elasticloadbalancingv2 and set internetFacing to true.
AWS
Need a hint?

Use new elbv2.NetworkLoadBalancer(this, 'myNLB', { vpc, internetFacing: true }) to create the NLB.

2
Add a listener on port 80
Add a listener to the Network Load Balancer myNLB on port 80 using TCP protocol. Use the addListener method with port: 80 and protocol: elbv2.Protocol.TCP.
AWS
Need a hint?

Use myNLB.addListener('Listener', { port: 80, protocol: elbv2.Protocol.TCP }) to add the listener.

3
Create a target group with TCP protocol
Create a target group called myTargetGroup with TCP protocol on port 80 in the default VPC. Use the NetworkTargetGroup construct from @aws-cdk/aws-elasticloadbalancingv2.
AWS
Need a hint?

Use new elbv2.NetworkTargetGroup(this, 'myTargetGroup', { vpc, port: 80, protocol: elbv2.Protocol.TCP }) to create the target group.

4
Add IP targets to the target group and attach to listener
Add two IP targets with IP addresses 10.0.0.10 and 10.0.0.11 to the target group myTargetGroup. Then attach myTargetGroup to the listener listener using the addTargetGroups method.
AWS
Need a hint?

Use myTargetGroup.addTarget(new elbv2.IpTarget('10.0.0.10', 80)) and similarly for the second IP. Then attach with listener.addTargetGroups('TargetGroupAttachment', { targetGroups: [myTargetGroup] }).