Class: AWSCDK::ECS::CfnTaskDefinition::PortMappingProperty

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

Overview

The PortMapping property specifies a port mapping.

Port mappings allow containers to access ports on the host container instance to send or receive traffic. Port mappings are specified as part of the container definition.

If you are using containers in a task with the awsvpc or host network mode, exposed ports should be specified using container_port . The host_port can be left blank or it must be the same value as the container_port .

After a task reaches the RUNNING status, manual and automatic host and container port assignments are visible in the network_bindings section of DescribeTasks API responses.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PortMappingProperty.

Parameters:

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

    The application protocol that's used for the port mapping.

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

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

  • 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 that's used for the port mapping.

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

    The protocol used for the port mapping.



2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
# File 'ecs/cfn_task_definition.rb', line 2688

def initialize(app_protocol: nil, container_port: nil, container_port_range: nil, host_port: nil, name: nil, protocol: nil)
  @app_protocol = app_protocol
  Jsii::Type.check_type(@app_protocol, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "appProtocol") unless @app_protocol.nil?
  @container_port = container_port
  Jsii::Type.check_type(@container_port, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "containerPort") unless @container_port.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("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "protocol") unless @protocol.nil?
end

Instance Attribute Details

#app_protocolString? (readonly)

The application protocol that's used for the port mapping.

This parameter only applies to Service Connect. We recommend that you set this parameter to be consistent with the protocol that your application uses. If you set this parameter, Amazon ECS adds protocol-specific connection handling to the Service Connect proxy. If you set this parameter, Amazon ECS adds protocol-specific telemetry in the Amazon ECS console and CloudWatch.

If you don't set a value for this parameter, then TCP is used. However, Amazon ECS doesn't add protocol-specific telemetry for TCP.

app_protocol is immutable in a Service Connect service. Updating this field requires a service deletion and redeployment.

Tasks that run in a namespace can use short names to connect to services in the namespace. Tasks can connect to services across all of the clusters in the namespace. Tasks connect through a managed proxy container that collects logs and metrics for increased visibility. Only the tasks that Amazon ECS services create are supported with Service Connect. For more information, see Service Connect in the Amazon Elastic Container Service Developer Guide .



2715
2716
2717
# File 'ecs/cfn_task_definition.rb', line 2715

def app_protocol
  @app_protocol
end

#container_portNumeric? (readonly)

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

If you use containers in a task with the awsvpc or host network mode, specify the exposed ports using container_port .

If you use 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 host_port . Port mappings that are automatically assigned in this way do not count toward the 100 reserved ports limit of a container instance.



2724
2725
2726
# File 'ecs/cfn_task_definition.rb', line 2724

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 use either the bridge network mode or the awsvpc network mode.
  • This parameter is available for both the EC2 and AWS Fargate launch types.
  • This parameter is available for both the Linux and Windows operating systems.
  • 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.
  • You do not specify a host_port_range . The value of the host_port_range is set as follows:
  • For containers in a task with the awsvpc network mode, the host_port_range is set to the same value as the container_port_range . This is a static mapping strategy.
  • For containers in a task with the bridge network mode, the Amazon ECS agent finds open host ports from the default ephemeral range and passes it to docker to bind them to the container ports.
  • The container_port_range valid values are between 1 and 65535.
  • 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.
  • Docker recommends that you turn off the docker-proxy in the Docker daemon config file when you have a large number of ports.

For more information, see Issue #11185 on the Github website.

For information about how to turn off the docker-proxy in the Docker daemon config file, see Docker daemon in the Amazon ECS Developer Guide .

You can call DescribeTasks to view the host_port_range which are the host ports that are bound to the container ports.



2751
2752
2753
# File 'ecs/cfn_task_definition.rb', line 2751

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 specify a container_port_range , leave this field empty and the value of the host_port is set as follows:

  • For containers in a task with the awsvpc network mode, the host_port is set to the same value as the container_port . This is a static mapping strategy.
  • For containers in a task with the bridge network mode, the Amazon ECS agent finds open ports on the host and automatically binds them to the container ports. This is a dynamic mapping strategy.

If you use containers in a task with the awsvpc or host network mode, the host_port can either be left blank or set to the same value as the container_port .

If you use 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 host_port (or set it to 0 ) while specifying a container_port and your container automatically receives a port in the ephemeral port range for your container instance operating system and Docker version.

The default ephemeral port range for Docker version 1.6.0 and later is listed on the instance under /proc/sys/net/ipv4/ip_local_port_range . If this kernel parameter is unavailable, the default ephemeral port range from 49153 through 65535 (Linux) or 49152 through 65535 (Windows) is used. Do not attempt to specify a host port in the ephemeral port range as these are reserved for automatic assignment. In general, ports below 32768 are outside of the ephemeral port range.

The default reserved ports are 22 for SSH, the Docker ports 2375 and 2376, and the Amazon ECS container agent ports 51678-51680. Any host port that was previously specified in a running task is also reserved while the task is running. That is, after a task stops, the host port is released. The current reserved ports are displayed in the remaining_resources of DescribeContainerInstances output. A container instance can have up to 100 reserved ports at a time. This number includes the default reserved ports. Automatically assigned ports aren't included in the 100 reserved ports quota.



2769
2770
2771
# File 'ecs/cfn_task_definition.rb', line 2769

def host_port
  @host_port
end

#nameString? (readonly)

The name that's used for the port mapping.

This parameter is the name that you use in the service_connect_configuration and the vpc_lattice_configurations of a service. The name can include up to 64 characters. The characters can include lowercase letters, numbers, underscores (_), and hyphens (-). The name can't start with a hyphen.



2776
2777
2778
# File 'ecs/cfn_task_definition.rb', line 2776

def name
  @name
end

#protocolString? (readonly)

The protocol used for the port mapping.

Valid values are tcp and udp . The default is tcp . protocol is immutable in a Service Connect service. Updating this field requires a service deletion and redeployment.



2783
2784
2785
# File 'ecs/cfn_task_definition.rb', line 2783

def protocol
  @protocol
end

Class Method Details

.jsii_propertiesObject



2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
# File 'ecs/cfn_task_definition.rb', line 2785

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

Instance Method Details

#to_jsiiObject



2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
# File 'ecs/cfn_task_definition.rb', line 2796

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