Skip to content

Commit 0efbe7e

Browse files
committed
revamp elb
1 parent f9e8aeb commit 0efbe7e

File tree

1 file changed

+30
-31
lines changed
  • src/content/docs/aws/services

1 file changed

+30
-31
lines changed

src/content/docs/aws/services/elb.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
title: "Elastic Load Balancing (ELB)"
3-
linkTitle: "Elastic Load Balancing (ELB)"
43
description: Get started with Elastic Load Balancing (ELB) on LocalStack
54
tags: ["Base"]
65
---
@@ -12,7 +11,7 @@ It also monitors the health of its registered targets and ensures that it routes
1211
You can check [the official AWS documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html) to understand the basic terms and concepts used in the ELB.
1312

1413
Localstack allows you to use the Elastic Load Balancing APIs in your local environment to create, edit, and view load balancers, target groups, listeners, and rules.
15-
The supported APIs are available on our [API coverage page]({{< ref "coverage_elbv2" >}}), which provides information on the extent of ELB's integration with LocalStack.
14+
The supported APIs are available on our [API coverage page](), which provides information on the extent of ELB's integration with LocalStack.
1615

1716
## Getting started
1817

@@ -25,90 +24,90 @@ We will demonstrate how to create an Application Load Balancer, along with its t
2524

2625
Launch an HTTP server which will serve as the target for our load balancer.
2726

28-
{{< command >}}
29-
$ docker run --rm -itd -p 5678:80 ealen/echo-server
30-
{{< /command >}}
27+
```bash
28+
docker run --rm -itd -p 5678:80 ealen/echo-server
29+
```
3130

3231
### Create a load balancer
3332

3433
To specify the subnet and VPC in which the load balancer will be created, you can use the [`DescribeSubnets`](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_DescribeSubnets.html) API to retrieve the subnet ID and VPC ID.
3534
In this example, we will use the subnet and VPC in the `us-east-1f` availability zone.
3635

37-
{{< command >}}
38-
$ subnet_info=$(awslocal ec2 describe-subnets --filters Name=availability-zone,Values=us-east-1f \
36+
```bash
37+
subnet_info=$(awslocal ec2 describe-subnets --filters Name=availability-zone,Values=us-east-1f \
3938
| jq -r '.Subnets[] | select(.AvailabilityZone == "us-east-1f") | {SubnetId: .SubnetId, VpcId: .VpcId}')
4039

41-
$ subnet_id=$(echo $subnet_info | jq -r '.SubnetId')
40+
subnet_id=$(echo $subnet_info | jq -r '.SubnetId')
4241

43-
$ vpc_id=$(echo $subnet_info | jq -r '.VpcId')
44-
{{< /command >}}
42+
vpc_id=$(echo $subnet_info | jq -r '.VpcId')
43+
```
4544

4645
To create a load balancer, you can use the [`CreateLoadBalancer`](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateLoadBalancer.html) API.
4746
The following command creates an Application Load Balancer named `example-lb`:
4847

49-
{{< command >}}
50-
$ loadBalancer=$(awslocal elbv2 create-load-balancer --name example-lb \
48+
```bash
49+
loadBalancer=$(awslocal elbv2 create-load-balancer --name example-lb \
5150
--subnets $subnet_id | jq -r '.LoadBalancers[]|.LoadBalancerArn')
52-
{{< /command >}}
51+
```
5352

5453
### Create a target group
5554

5655
To create a target group, you can use the [`CreateTargetGroup`](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateTargetGroup.html) API.
5756
The following command creates a target group named `example-target-group`:
5857

59-
{{< command >}}
60-
$ targetGroup=$(awslocal elbv2 create-target-group --name example-target-group \
58+
```bash
59+
targetGroup=$(awslocal elbv2 create-target-group --name example-target-group \
6160
--protocol HTTP --target-type ip --port 80 --vpc-id $vpc_id \
6261
| jq -r '.TargetGroups[].TargetGroupArn')
63-
{{< /command >}}
62+
```
6463

6564
### Register a target
6665

6766
To register a target, you can use the [`RegisterTargets`](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_RegisterTargets.html) API.
6867
The following command registers the target with the target group created in the previous step:
6968

70-
{{< command >}}
71-
$ awslocal elbv2 register-targets --targets Id=127.0.0.1,Port=5678,AvailabilityZone=all \
69+
```bash
70+
awslocal elbv2 register-targets --targets Id=127.0.0.1,Port=5678,AvailabilityZone=all \
7271
--target-group-arn $targetGroup
73-
{{< /command >}}
72+
```
7473

75-
{{< callout >}}
74+
:::note
7675
Note that in some cases the `targets` parameter `Id` can be the `Gateway` address of the docker container.
7776
You can find the gateway address by running `docker inspect <container_id>`.
78-
{{< /callout >}}
77+
:::
7978

8079
### Create a listener and a rule
8180

8281
We create a listener for the load balancer using the [`CreateListener`](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateListener.html) API.
8382
The following command creates a listener for the load balancer created in the previous step:
8483

85-
{{< command >}}
86-
$ listenerArn=$(awslocal elbv2 create-listener \
84+
```bash
85+
listenerArn=$(awslocal elbv2 create-listener \
8786
--protocol HTTP \
8887
--port 80 \
8988
--default-actions '{"Type":"forward","TargetGroupArn":"'$targetGroup'","ForwardConfig":{"TargetGroups":[{"TargetGroupArn":"'$targetGroup'","Weight":11}]}}' \
9089
--load-balancer-arn $loadBalancer | jq -r '.Listeners[]|.ListenerArn')
91-
{{< /command >}}
90+
```
9291

9392
To create a rule for the listener, you can use the [`CreateRule`](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateRule.html) API.
9493
The following command creates a rule for the listener created above:
9594

96-
{{< command >}}
97-
$ listenerRule=$(awslocal elbv2 create-rule \
95+
```bash
96+
listenerRule=$(awslocal elbv2 create-rule \
9897
--conditions Field=path-pattern,Values=/ \
9998
--priority 1 \
10099
--actions '{"Type":"forward","TargetGroupArn":"'$targetGroup'","ForwardConfig":{"TargetGroups":[{"TargetGroupArn":"'$targetGroup'","Weight":11}]}}' \
101100
--listener-arn $listenerArn \
102101
| jq -r '.Rules[].RuleArn')
103-
{{< /command >}}
102+
```
104103

105104
### Send a request to the load balancer
106105

107106
Finally, you can issue an HTTP request to the `DNSName` parameter of `CreateLoadBalancer` operation, and `Port` parameter of `CreateListener` command with the following command:
108107

109-
{{< command >}}
110-
$ curl example-lb.elb.localhost.localstack.cloud:4566
111-
{{< /command >}}
108+
```bash
109+
curl example-lb.elb.localhost.localstack.cloud:4566
110+
```
112111

113112
The following output will be retrieved:
114113

@@ -175,7 +174,7 @@ http(s)://localhost.localstack.cloud:4566/_aws/elb/example-lb/test/path
175174

176175
The following code snippets and sample applications provide practical examples of how to use ELB in LocalStack for various use cases:
177176

178-
- [Setting up Elastic Load Balancing (ELB) Application Load Balancers using LocalStack, deployed via the Serverless framework]({{< ref "/tutorials/elb-load-balancing" >}})
177+
- [Setting up Elastic Load Balancing (ELB) Application Load Balancers using LocalStack, deployed via the Serverless framework]()
179178

180179
## Current Limitations
181180

0 commit comments

Comments
 (0)