0

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

Jhansi
  • 1

1 Answers1

0

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]);
gshpychka
  • 8,523
  • 1
  • 11
  • 31