skip to Main Content

I am trying to attach security group to the Network Load Balancer through CDK. I do not see an option in the constructor properties. I know it’s a new feature that NLB supporting security group. Please suggest.

Here is the CDK documentation I was referring to

https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.NetworkLoadBalancer.html

https://aws.amazon.com/about-aws/whats-new/2023/08/network-load-balancer-supports-security-groups/

Looking if someone tried to associate security group in NLB through CDK

2

Answers


  1. This is documentation for the CDK version 2.93.0. Update CDK to the latest version.

    Login or Signup to reply.
  2. This has not been released in CDK yet as of 2.93.0 – here is the relevant issue that contains a temporary workaround using an escape hatch:

    const lb = new elasticloadbalancingv2.NetworkLoadBalancer(this, "nyancatNlb", {
      vpc,
    });
    
    const nlbSg = new ec2.SecurityGroup(this, "NLBSecurityGroup", { vpc });
    
    const cfnlb = lb.node.defaultChild as elasticloadbalancingv2.CfnLoadBalancer;
    
    cfnlb.addPropertyOverride("SecurityGroups", [nlbSg.securityGroupId]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search