Skip to content

Load balancing

To have an application accessible from the internet you need a load balancer that can route traffic to the application.

The load balancer set up for your environment is {Environment}-public.

Step 1: Create a new configuration file

Create a new configuration file for load balancing:

repo-iac/environments/dev/_config/load-balancing-alb-main.yml
StackName: "load-balancing-alb-main"
load-balancing-alb-data.StackName: "load-balancing-alb-main-data"
Internal: false

Name: "main"

Name: "main" must match the name in load-balancing-alb-main-data.StackName.

Step 2: Add and install the load-balancing package

Run the following command in the repo-iac/environments/dev/ directory:

repo-iac/environments/dev/
ok pkg add load-balancing-alb load-balancing-alb-main

This will add the package you want to install to packages.yml. If you want to know more about how this works, read the reference documentation for packages.yml.

Then, run the following command to install the package:

repo-iac/environments/dev/
ok pkg install load-balancing-alb-main

Step 3: Initialize and apply the load-balancing stacks

ALB are separated into two stacks when creating them.

The first stack is the data stack, which contains data-related resources, this must be applied first.

The second stack is the alb stack, which contains the load balancing set up, route53, etc.

repo-iac/environments/dev/
cd load-balancing-alb-main-data/
terraform init
terraform apply
repo-iac/environments/dev/
cd load-balancing-alb-main/
terraform init
terraform apply

Step 4: Verify

Run the following command:

aws elbv2 describe-load-balancers | jq '.LoadBalancers[].LoadBalancerName'

The output list should contain the name of the load balancer you just created.

Login to the AWS console and navigate to EC2. Select Load Balancers in the left-hand menu.

The list should contain the name of the load balancer you just created.


Commit your files

At this stage it is a good idea to commit your files.

Next step

Set up IAM.