Port

class aws_cdk.aws_ec2.Port(*, protocol, string_representation, from_port=None, to_port=None)

Bases: object

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

ExampleMetadata:

infused

Example:

# load_balancer: elbv2.ApplicationLoadBalancer


vpc = ec2.Vpc(self, "MyVPC")
project = codebuild.Project(self, "MyProject",
    vpc=vpc,
    build_spec=codebuild.BuildSpec.from_object({})
)

project.connections.allow_to(load_balancer, ec2.Port.tcp(443))
Parameters:
  • protocol (Protocol) – The protocol for the range.

  • string_representation (str) – String representation for this object.

  • from_port (Union[int, float, None]) – The starting port for the range. Default: - Not included in the rule

  • to_port (Union[int, float, None]) – The ending port for the range. Default: - Not included in the rule

Methods

to_rule_json()

Produce the ingress/egress rule JSON for the given connection.

Return type:

Any

to_string()
Return type:

str

Attributes

can_inline_rule

Whether the rule containing this port range can be inlined into a securitygroup or not.

Static Methods

classmethod ah()

A single AH port.

Return type:

Port

classmethod all_icmp()

All ICMP traffic.

Return type:

Port

classmethod all_tcp()

Any TCP traffic.

Return type:

Port

classmethod all_traffic()

All traffic.

Return type:

Port

classmethod all_udp()

Any UDP traffic.

Return type:

Port

classmethod esp()

A single ESP port.

Return type:

Port

classmethod icmp_ping()

ICMP ping (echo) traffic.

Return type:

Port

classmethod icmp_type(type)

All codes for a single ICMP type.

Parameters:

type (Union[int, float]) –

Return type:

Port

classmethod icmp_type_and_code(type, code)

A specific combination of ICMP type and code.

Parameters:
  • type (Union[int, float]) –

  • code (Union[int, float]) –

See:

https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml

Return type:

Port

classmethod tcp(port)

A single TCP port.

Parameters:

port (Union[int, float]) –

Return type:

Port

classmethod tcp_range(start_port, end_port)

A TCP port range.

Parameters:
  • start_port (Union[int, float]) –

  • end_port (Union[int, float]) –

Return type:

Port

classmethod udp(port)

A single UDP port.

Parameters:

port (Union[int, float]) –

Return type:

Port

classmethod udp_range(start_port, end_port)

A UDP port range.

Parameters:
  • start_port (Union[int, float]) –

  • end_port (Union[int, float]) –

Return type:

Port