如何在aws cdk中添加from和to端口?

2024-05-19 12:03:23 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我在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。有人能帮我吗?任何帮助都将不胜感激。谢谢


Tags: 端口awsref规则sgconnectionsvpctcp
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

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

因此aws_ec2.Port(aws_ec2.TCP, 31000, 65535)行中的某些内容应该可以起到作用

相关问题 更多 >

    热门问题