【问题标题】:How to add from and to port in aws cdk?如何在 aws cdk 中添加从端口到端口?
【发布时间】:2020-04-27 03:34:38
【问题描述】:

您好,我正在研究 aws cdk。我使用云形成创建了早期的入口规则,如下所示。

 - IpProtocol: tcp
     FromPort: 31000
     ToPort: 65535
     SourceSecurityGroupId: !Ref MerchWebServicesLoadBalancerSecurityGroup

我可以如下添加端口 80 或 443

mws_vpc_sg.connections.allow_from(mws_vpc_sg_alb,ec2.Port.tcp(443))

如何指定从端口 31000 到端口 65353。有人可以帮助我吗?任何帮助,将不胜感激。谢谢

【问题讨论】:

    标签: python amazon-web-services aws-security-group aws-cdk


    【解决方案1】:

    你给它一个Port 类型的参数。见Port documentation

    所以aws_ec2.Port(aws_ec2.TCP, 31000, 65535) 行中的内容应该可以解决问题。

    【讨论】:

    • 我给了这样的东西 mws_vpc_sg.connections.allow_to(other =mws_vpc_sg_alb,port_range=ec2.Port(ec2.Port.tcp, 'string', 31000, 65535)) 但它给了我错误 TypeError : __init__() 接受 1 个位置参数,但给出了 5 个
    【解决方案2】:

    我添加了以下代码并开始为我工作。

    mws_vpc_sg.add_ingress_rule(peer= ec2.Peer.ipv4('172.30.0.0/15'), connection = ec2.Port.tcp_range(31000,655353))
    

    这会产生

    MerchWebServicesSecurityGroup4BA36B9B:
        Type: AWS::EC2::SecurityGroup
        Properties:
          GroupDescription: EC2 Services Security Group
          GroupName: MerchWebServicesSecurityGroup
          SecurityGroupEgress:
            - CidrIp: 0.0.0.0/0
              Description: Allow all outbound traffic by default
              IpProtocol: "-1"
          SecurityGroupIngress:
            - CidrIp: 172.30.0.0/15
              Description: from 172.30.0.0/15:31000-655353
              FromPort: 31000
              IpProtocol: tcp
              ToPort: 655353
          VpcId: vpc-839227e7
    

    【讨论】:

      猜你喜欢
      • 2022-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-27
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多