Class: AWSCDK::ECS::PortMapping

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
ecs/port_mapping.rb

Overview

Port mappings allow containers to access ports on the host container instance to send or receive traffic.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container_port:, app_protocol: nil, container_port_range: nil, host_port: nil, name: nil, protocol: nil) ⇒ PortMapping

Returns a new instance of PortMapping.

Parameters:

  • container_port (Numeric)

    The port number on the container that is bound to the user-specified or automatically assigned host port.

  • app_protocol (AWSCDK::ECS::AppProtocol, nil) (defaults to: nil)

    The protocol used by Service Connect.

  • container_port_range (String, nil) (defaults to: nil)

    The port number range on the container that's bound to the dynamically mapped host port range.

  • host_port (Numeric, nil) (defaults to: nil)

    The port number on the container instance to reserve for your container.

  • name (String, nil) (defaults to: nil)

    The name to give the port mapping.

  • protocol (AWSCDK::ECS::Protocol, nil) (defaults to: nil)

    The protocol used for the port mapping.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'ecs/port_mapping.rb', line 13

def initialize(container_port:, app_protocol: nil, container_port_range: nil, host_port: nil, name: nil, protocol: nil)
  @container_port = container_port
  Jsii::Type.check_type(@container_port, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "containerPort")
  @app_protocol = app_protocol
  Jsii::Type.check_type(@app_protocol, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWNzLkFwcFByb3RvY29sIn0=")), "appProtocol") unless @app_protocol.nil?
  @container_port_range = container_port_range
  Jsii::Type.check_type(@container_port_range, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "containerPortRange") unless @container_port_range.nil?
  @host_port = host_port
  Jsii::Type.check_type(@host_port, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "hostPort") unless @host_port.nil?
  @name = name
  Jsii::Type.check_type(@name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "name") unless @name.nil?
  @protocol = protocol
  Jsii::Type.check_type(@protocol, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfZWNzLlByb3RvY29sIn0=")), "protocol") unless @protocol.nil?
end

Instance Attribute Details

#app_protocolAWSCDK::ECS::AppProtocol? (readonly)

Note:

Default: - no app protocol

The protocol used by Service Connect.

Valid values are AppProtocol.http, AppProtocol.http2, and AppProtocol.grpc. The protocol determines what telemetry will be shown in the ECS Console for Service Connect services using this port mapping.

This field may only be set when the task definition uses Bridge or Awsvpc network modes.

Returns:



51
52
53
# File 'ecs/port_mapping.rb', line 51

def app_protocol
  @app_protocol
end

#container_portNumeric (readonly)

The port number on the container that is bound to the user-specified or automatically assigned host port.

If you are using containers in a task with the awsvpc or host network mode, exposed ports should be specified using containerPort. If you are using containers in a task with the bridge network mode and you specify a container port and not a host port, your container automatically receives a host port in the ephemeral port range.

For more information, see hostPort. Port mappings that are automatically assigned in this way do not count toward the 100 reserved ports limit of a container instance.

If you want to expose a port range, you must specify CONTAINER_PORT_USE_RANGE as container port.

Returns:

  • (Numeric)


40
41
42
# File 'ecs/port_mapping.rb', line 40

def container_port
  @container_port
end

#container_port_rangeString? (readonly)

The port number range on the container that's bound to the dynamically mapped host port range.

The following rules apply when you specify a container_port_range:

  • You must specify CONTAINER_PORT_USE_RANGE as container_port
  • You must use either the bridge network mode or the awsvpc network mode.
  • The container instance must have at least version 1.67.0 of the container agent and at least version 1.67.0-1 of the ecs-init package
  • You can specify a maximum of 100 port ranges per container.
  • A port can only be included in one port mapping per container.
  • You cannot specify overlapping port ranges.
  • The first port in the range must be less than last port in the range.

If you want to expose a single port, you must not set a range.

Returns:

  • (String, nil)


67
68
69
# File 'ecs/port_mapping.rb', line 67

def container_port_range
  @container_port_range
end

#host_portNumeric? (readonly)

The port number on the container instance to reserve for your container.

If you are using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort.

If you are using containers in a task with the bridge network mode, you can specify a non-reserved host port for your container port mapping, or you can omit the hostPort (or set it to 0) while specifying a containerPort and your container automatically receives a port in the ephemeral port range for your container instance operating system and Docker version.

Returns:

  • (Numeric, nil)


80
81
82
# File 'ecs/port_mapping.rb', line 80

def host_port
  @host_port
end

#nameString? (readonly)

Note:

Default: - no port mapping name

The name to give the port mapping.

Name is required in order to use the port mapping with ECS Service Connect. This field may only be set when the task definition uses Bridge or Awsvpc network modes.

Returns:

  • (String, nil)


88
89
90
# File 'ecs/port_mapping.rb', line 88

def name
  @name
end

#protocolAWSCDK::ECS::Protocol? (readonly)

Note:

Default: TCP

The protocol used for the port mapping.

Valid values are Protocol.TCP and Protocol.UDP.

Returns:



95
96
97
# File 'ecs/port_mapping.rb', line 95

def protocol
  @protocol
end

Class Method Details

.jsii_propertiesObject



97
98
99
100
101
102
103
104
105
106
# File 'ecs/port_mapping.rb', line 97

def self.jsii_properties
  {
    :container_port => "containerPort",
    :app_protocol => "appProtocol",
    :container_port_range => "containerPortRange",
    :host_port => "hostPort",
    :name => "name",
    :protocol => "protocol",
  }
end

Instance Method Details

#to_jsiiObject



108
109
110
111
112
113
114
115
116
117
118
119
# File 'ecs/port_mapping.rb', line 108

def to_jsii
  result = {}
  result.merge!({
    "containerPort" => @container_port,
    "appProtocol" => @app_protocol,
    "containerPortRange" => @container_port_range,
    "hostPort" => @host_port,
    "name" => @name,
    "protocol" => @protocol,
  })
  result.compact
end