Skip to content

Commit 78a7182

Browse files
chore(elasticloadbalancingv2): add details about Network Load Balancer and EC2 IConnectable interface. (#31704)
### Issue # (if applicable) Closes #31644. ### Reason for this change User reported that using `connections` with NLB without security group specified, doesn't create security group automatically. NLB do not have security groups, and no automatic security group configuration is done. ### Description of changes Add details about Network Load Balancer and EC2 `IConnectable` interface. ### Description of how you validated changes ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1db9be7 commit 78a7182

File tree

1 file changed

+17
-0
lines changed
  • packages/aws-cdk-lib/aws-elasticloadbalancingv2

1 file changed

+17
-0
lines changed

packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,23 @@ const listener = lb.addListener('Listener', {
422422
});
423423
```
424424

425+
### Network Load Balancer and EC2 IConnectable interface
426+
Network Load Balancer implements EC2 `IConnectable` and exposes `connections` property. EC2 Connections allows manage the allowed network connections for constructs with Security Groups. This class makes it easy to allow network connections to and from security groups, and between security groups individually. One thing to keep in mind is that network load balancers do not have security groups, and no automatic security group configuration is done for you. You will have to configure the security groups of the target yourself to allow traffic by clients and/or load balancer instances, depending on your target types.
427+
428+
```ts
429+
declare const vpc: ec2.Vpc;
430+
declare const sg1: ec2.ISecurityGroup;
431+
declare const sg2: ec2.ISecurityGroup;
432+
433+
const lb = new elbv2.NetworkLoadBalancer(this, 'LB', {
434+
vpc,
435+
internetFacing: true,
436+
securityGroups: [sg1],
437+
});
438+
lb.addSecurityGroup(sg2);
439+
lb.connections.allowFromAnyIpv4(ec2.Port.tcp(80));
440+
```
441+
425442
## Targets and Target Groups
426443

427444
Application and Network Load Balancers organize load balancing targets in Target

0 commit comments

Comments
 (0)