> **Page index:** https://km.oslo.systems/llms.txt lists every page on this site, with a link to its Markdown version.

# Set up 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
```

The name `main` is used here because there is only one load balancer. If you have many 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

```
# Setup load balancing
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/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/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.

Sign in 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.

---

You're done with the Networking setup.

## Next step

Set up [databases](<https://km.oslo.systems/initial-setup-of-your-aws-environment/set-up-databases/index.md>).
