简体   繁体   中英

CDK elbv2.ApplicationLoadBalancer.add_security_group doesn't work

CDK Python latest.

I'm doing a:

something = elbv2.ApplicationLoadBalancer(
...
)

something.add_security_group(securitygroupid)

and I'm getting a error:

AttributeError: 'ApplicationLoadBalancer' object has no attribute 'add_security_group" when in the CDK docs, it says there is a method? bug?

I was able to run cdk synth and it didn't complain about the add_security_group.

Which version of the CDK are you using ?

See the dummy example below. I'm using aws-cdk version 1.64.1

from aws_cdk import core

import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_elasticloadbalancingv2 as elbv2
import aws_cdk.aws_elasticloadbalancingv2_targets as targets


class CdkPythonStack(core.Stack):

  def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
    super().__init__(scope, id, **kwargs)

    vpc = ec2.Vpc(self, 'vpc')

    instance = ec2.Instance(self, 'instance', vpc=vpc, instance_type=ec2.InstanceType(
      't3.nano'), machine_image=ec2.MachineImage.latest_amazon_linux())

    alb = elbv2.ApplicationLoadBalancer(self, 'alb', vpc=vpc)

    alb.add_security_group(ec2.SecurityGroup(self, 'sg', vpc=vpc))

    listener = alb.add_listener('listener', port=80)

    listener.add_targets('ec2_instance', port=8080, targets=[
                         targets.InstanceIdTarget(instance_id=instance.instance_id, port=8080)])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM