Skip to content

Commit

Permalink
chore(elasticloadbalancingv2): add details about Network Load Balance…
Browse files Browse the repository at this point in the history
…r 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*
  • Loading branch information
ashishdhingra authored Oct 14, 2024
1 parent 1db9be7 commit 78a7182
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/aws-elasticloadbalancingv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,23 @@ const listener = lb.addListener('Listener', {
});
```

### Network Load Balancer and EC2 IConnectable interface
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.

```ts
declare const vpc: ec2.Vpc;
declare const sg1: ec2.ISecurityGroup;
declare const sg2: ec2.ISecurityGroup;

const lb = new elbv2.NetworkLoadBalancer(this, 'LB', {
vpc,
internetFacing: true,
securityGroups: [sg1],
});
lb.addSecurityGroup(sg2);
lb.connections.allowFromAnyIpv4(ec2.Port.tcp(80));
```

## Targets and Target Groups

Application and Network Load Balancers organize load balancing targets in Target
Expand Down

0 comments on commit 78a7182

Please sign in to comment.