Class: AWSCDK::ECS::PortMapping
- Inherits:
-
Jsii::Struct
- Object
- Jsii::Struct
- AWSCDK::ECS::PortMapping
- 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
-
#app_protocol ⇒ AWSCDK::ECS::AppProtocol?
readonly
The protocol used by Service Connect.
-
#container_port ⇒ Numeric
readonly
The port number on the container that is bound to the user-specified or automatically assigned host port.
-
#container_port_range ⇒ String?
readonly
The port number range on the container that's bound to the dynamically mapped host port range.
-
#host_port ⇒ Numeric?
readonly
The port number on the container instance to reserve for your container.
-
#name ⇒ String?
readonly
The name to give the port mapping.
-
#protocol ⇒ AWSCDK::ECS::Protocol?
readonly
The protocol used for the port mapping.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(container_port:, app_protocol: nil, container_port_range: nil, host_port: nil, name: nil, protocol: nil) ⇒ PortMapping
constructor
A new instance of PortMapping.
- #to_jsii ⇒ Object
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.
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_protocol ⇒ AWSCDK::ECS::AppProtocol? (readonly)
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.
51 52 53 |
# File 'ecs/port_mapping.rb', line 51 def app_protocol @app_protocol end |
#container_port ⇒ Numeric (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.
40 41 42 |
# File 'ecs/port_mapping.rb', line 40 def container_port @container_port end |
#container_port_range ⇒ String? (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_RANGEascontainer_port - You must use either the
bridgenetwork mode or theawsvpcnetwork 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-initpackage - 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.
67 68 69 |
# File 'ecs/port_mapping.rb', line 67 def container_port_range @container_port_range end |
#host_port ⇒ Numeric? (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.
80 81 82 |
# File 'ecs/port_mapping.rb', line 80 def host_port @host_port end |
#name ⇒ String? (readonly)
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.
88 89 90 |
# File 'ecs/port_mapping.rb', line 88 def name @name end |
#protocol ⇒ AWSCDK::ECS::Protocol? (readonly)
Default: TCP
The protocol used for the port mapping.
Valid values are Protocol.TCP and Protocol.UDP.
95 96 97 |
# File 'ecs/port_mapping.rb', line 95 def protocol @protocol end |
Class Method Details
.jsii_properties ⇒ Object
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_jsii ⇒ Object
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 |