Skip to content
v2.273.0

Port Class ​

Interface for classes that provide the connection-specification parts of a security group rule.

Example ​

ts
declare const loadBalancer: elbv2.ApplicationLoadBalancer;

const vpc = new ec2.Vpc(this, 'MyVPC');
const fleet = new codebuild.Fleet(this, 'MyProject', {
  computeType: codebuild.FleetComputeType.MEDIUM,
  environmentType: codebuild.EnvironmentType.LINUX_CONTAINER,
  baseCapacity: 1,
  vpc,
});

fleet.connections.allowTo(loadBalancer, ec2.Port.tcp(443));

const project = new codebuild.Project(this, 'MyProject', {
  environment: {
    fleet,
  },
  buildSpec: codebuild.BuildSpec.fromObject({
    // ...
  }),
  // Trying to configure a project-level VPC is an error, because this project
  // runs on the Fleet created above.
  // vpc,
});
python
# load_balancer: elbv2.ApplicationLoadBalancer


vpc = ec2.Vpc(self, "MyVPC")
fleet = codebuild.Fleet(self, "MyProject",
    compute_type=codebuild.FleetComputeType.MEDIUM,
    environment_type=codebuild.EnvironmentType.LINUX_CONTAINER,
    base_capacity=1,
    vpc=vpc
)

fleet.connections.allow_to(load_balancer, ec2.Port.tcp(443))

project = codebuild.Project(self, "MyProject",
    environment=codebuild.BuildEnvironment(
        fleet=fleet
    ),
    build_spec=codebuild.BuildSpec.from_object({})
)
java
ApplicationLoadBalancer loadBalancer;


Vpc vpc = new Vpc(this, "MyVPC");
Fleet fleet = Fleet.Builder.create(this, "MyProject")
        .computeType(FleetComputeType.MEDIUM)
        .environmentType(EnvironmentType.LINUX_CONTAINER)
        .baseCapacity(1)
        .vpc(vpc)
        .build();

fleet.connections.allowTo(loadBalancer, Port.tcp(443));

Project project = Project.Builder.create(this, "MyProject")
        .environment(BuildEnvironment.builder()
                .fleet(fleet)
                .build())
        .buildSpec(BuildSpec.fromObject(Map.of()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
ApplicationLoadBalancer loadBalancer;


var vpc = new Vpc(this, "MyVPC");
var fleet = new Fleet(this, "MyProject", new FleetProps {
    ComputeType = FleetComputeType.MEDIUM,
    EnvironmentType = EnvironmentType.LINUX_CONTAINER,
    BaseCapacity = 1,
    Vpc = vpc
});

fleet.Connections.AllowTo(loadBalancer, Port.Tcp(443));

var project = new Project(this, "MyProject", new ProjectProps {
    Environment = new BuildEnvironment {
        Fleet = fleet
    },
    BuildSpec = BuildSpec.FromObject(new Dictionary<string, object> { })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var loadBalancer ApplicationLoadBalancer


vpc := ec2.NewVpc(this, jsii.String("MyVPC"))
fleet := codebuild.NewFleet(this, jsii.String("MyProject"), &FleetProps{
	ComputeType: codebuild.FleetComputeType_MEDIUM,
	EnvironmentType: codebuild.EnvironmentType_LINUX_CONTAINER,
	BaseCapacity: jsii.Number(1),
	Vpc: Vpc,
})

fleet.connections.AllowTo(loadBalancer, ec2.Port_Tcp(jsii.Number(443)))

project := codebuild.NewProject(this, jsii.String("MyProject"), &ProjectProps{
	Environment: &BuildEnvironment{
		Fleet: *Fleet,
	},
	BuildSpec: codebuild.BuildSpec_FromObject(map[string]interface{}{
	}),
})

Initializer ​

ts
new Port(props: PortProps)
python
Port(props: PortProps)
java
new Port(PortProps props)
csharp
new Port(PortProps props)
go
NewPort(Props PortProps)

Properties ​

canInlineRulebooleancan_inline_ruleboolcanInlineRuleBooleanCanInlineRuleboolCanInlineRule*boolrequired#
Whether the rule containing this port range can be inlined into a securitygroup or not.
DNS_TCPPortdns_tcpPortDNS_TCPPortDNS_TCPPortDNS_TCPPortrequiredstatic#
Well-known DNS port (TCP 53).
DNS_UDPPortdns_udpPortDNS_UDPPortDNS_UDPPortDNS_UDPPortrequiredstatic#
Well-known DNS port (UDP 53).
HTTPPorthttpPortHTTPPortHTTPPortHTTPPortrequiredstatic#
Well-known HTTP port (TCP 80).
HTTPSPorthttpsPortHTTPSPortHTTPSPortHTTPSPortrequiredstatic#
Well-known HTTPS port (TCP 443).
IMAPPortimapPortIMAPPortIMAPPortIMAPPortrequiredstatic#
Well-known IMAP port (TCP 143).
IMAPSPortimapsPortIMAPSPortIMAPSPortIMAPSPortrequiredstatic#
Well-known IMAPS port (TCP 993).
LDAPPortldapPortLDAPPortLDAPPortLDAPPortrequiredstatic#
Well-known LDAP port (TCP 389).
MSSQLPortmssqlPortMSSQLPortMSSQLPortMSSQLPortrequiredstatic#
Well-known Microsoft SQL Server port (TCP 1433).
MYSQL_AURORAPortmysql_auroraPortMYSQL_AURORAPortMYSQL_AURORAPortMYSQL_AURORAPortrequiredstatic#
Well-known MySQL and Aurora port (TCP 3306).
NFSPortnfsPortNFSPortNFSPortNFSPortrequiredstatic#
Well-known NFS port (TCP 2049).
POP3Portpop3PortPOP3PortPOP3PortPOP3Portrequiredstatic#
Well-known POP3 port (TCP 110).
POP3SPortpop3_sPortPOP3SPortPOP3SPortPOP3SPortrequiredstatic#
Well-known POP3S port (TCP 995).
POSTGRESPortpostgresPortPOSTGRESPortPOSTGRESPortPOSTGRESPortrequiredstatic#
Well-known PostgreSQL port (TCP 5432).
RDPPortrdpPortRDPPortRDPPortRDPPortrequiredstatic#
Well-known Microsoft Remote Desktop Protocol port (TCP 3389).
SMBPortsmbPortSMBPortSMBPortSMBPortrequiredstatic#
Well-known SMB port (TCP 445).
SMTPPortsmtpPortSMTPPortSMTPPortSMTPPortrequiredstatic#
Well-known SMTP port (TCP 25).
SSHPortsshPortSSHPortSSHPortSSHPortrequiredstatic#
Well-known SSH port (TCP 22).

Methods ​

ah(): Port // chainable@staticmethod def ah() -> Portpublic static Port ah()public static Port Ah()func Ah() Portstatic#
A single AH port.
allIcmp(): Port // chainable@staticmethod def all_icmp() -> Portpublic static Port allIcmp()public static Port AllIcmp()func AllIcmp() Portstatic#
All ICMP traffic.
allIcmpV6(): Port // chainable@staticmethod def all_icmp_v6() -> Portpublic static Port allIcmpV6()public static Port AllIcmpV6()func AllIcmpV6() Portstatic#
All ICMPv6 traffic.
allTcp(): Port // chainable@staticmethod def all_tcp() -> Portpublic static Port allTcp()public static Port AllTcp()func AllTcp() Portstatic#
Any TCP traffic.
allTraffic(): Port // chainable@staticmethod def all_traffic() -> Portpublic static Port allTraffic()public static Port AllTraffic()func AllTraffic() Portstatic#
All traffic.
allUdp(): Port // chainable@staticmethod def all_udp() -> Portpublic static Port allUdp()public static Port AllUdp()func AllUdp() Portstatic#
Any UDP traffic.
esp(): Port // chainable@staticmethod def esp() -> Portpublic static Port esp()public static Port Esp()func Esp() Portstatic#
A single ESP port.
icmpPing(): Port // chainable@staticmethod def icmp_ping() -> Portpublic static Port icmpPing()public static Port IcmpPing()func IcmpPing() Portstatic#
ICMP ping (echo) traffic.
icmpType(type: number): Port // chainable@staticmethod def icmp_type(type: int | float) -> Portpublic static Port icmpType(Number type)public static Port IcmpType(double type)func IcmpType(Type *float64) Portstatic#
All codes for a single ICMP type.
icmpTypeAndCode(type: number, code: number): Port // chainable@staticmethod def icmp_type_and_code(type: int | float, code: int | float) -> Portpublic static Port icmpTypeAndCode(Number type, Number code)public static Port IcmpTypeAndCode(double type, double code)func IcmpTypeAndCode(Type *float64, Code *float64) Portstatic#
A specific combination of ICMP type and code.
tcp(port: number): Port // chainable@staticmethod def tcp(port: int | float) -> Portpublic static Port tcp(Number port)public static Port Tcp(double port)func Tcp(Port *float64) Portstatic#
A single TCP port.
tcpRange(startPort: number, endPort: number): Port // chainable@staticmethod def tcp_range(start_port: int | float, end_port: int | float) -> Portpublic static Port tcpRange(Number startPort, Number endPort)public static Port TcpRange(double startPort, double endPort)func TcpRange(StartPort *float64, EndPort *float64) Portstatic#
A TCP port range.
toRuleJson(): anydef to_rule_json(self, ) -> Anypublic Object toRuleJson()public object ToRuleJson()func ToRuleJson() interface{}#
Produce the ingress/egress rule JSON for the given connection.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
udp(port: number): Port // chainable@staticmethod def udp(port: int | float) -> Portpublic static Port udp(Number port)public static Port Udp(double port)func Udp(Port *float64) Portstatic#
A single UDP port.
udpRange(startPort: number, endPort: number): Port // chainable@staticmethod def udp_range(start_port: int | float, end_port: int | float) -> Portpublic static Port udpRange(Number startPort, Number endPort)public static Port UdpRange(double startPort, double endPort)func UdpRange(StartPort *float64, EndPort *float64) Portstatic#
A UDP port range.