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: Add and configure the load-balancing package

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

We chose main here because we have just one load balancer. If you have multiple load balancers, you can replace main with something more descriptive (for instance "payments", "catalog", "orders").

Update package-config.yml with your preferences. The Name field should be main (or whatever you chose above) to avoid confusion:

repo-iac/environments/dev/load-balancing-alb-main/package-config.yml
# ...
Name: "main"
# ...

Step 2: Install the package

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

Step 3: Apply in this order (required)

Order matters: Apply data first, then alb. The alb stack depends on resources created by the data stack.

1) Apply the data stack (required first)

Creates S3 buckets for logs and other data resources.

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

2) Apply the alb stack (run second)

Creates the Application Load Balancer, Route53 records, and other resources.

# 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.


Next step

Set up IAM.