Reputation: 2229
Hi I am working on aws cdk. I have created earlier ingress rules using cloud formation as below.
- IpProtocol: tcp
FromPort: 31000
ToPort: 65535
SourceSecurityGroupId: !Ref MerchWebServicesLoadBalancerSecurityGroup
I can add port 80 or 443 as below
mws_vpc_sg.connections.allow_from(mws_vpc_sg_alb,ec2.Port.tcp(443))
How can I specify from port 31000 and to port 65353. Can some one help me in this? Any help would be appreciated. Thanks
Upvotes: 1
Views: 1957
Reputation: 2229
I added below code and started working for me.
mws_vpc_sg.add_ingress_rule(peer= ec2.Peer.ipv4('172.30.0.0/15'), connection = ec2.Port.tcp_range(31000,655353))
This will produce
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
Upvotes: 2
Reputation: 30167
You give it a Port
type argument. See Port documentation.
So something in lines of aws_ec2.Port(aws_ec2.TCP, 31000, 65535)
should do the trick.
Upvotes: 0