EcsTarget

class aws_cdk.aws_ecs.EcsTarget(*, container_name, listener, new_target_group_id, container_port=None, protocol=None)

Bases: object

Parameters
  • container_name (str) – The name of the container.

  • listener (ListenerConfig) – Listener and properties for adding target group to the listener.

  • new_target_group_id (str) – ID for a target group to be created.

  • container_port (Union[int, float, None]) – The port number of the container. Only applicable when using application/network load balancers. Default: - Container port of the first added port mapping.

  • protocol (Optional[Protocol]) – The protocol used for the port mapping. Only applicable when using application load balancers. Default: Protocol.TCP

Example:

# cluster is of type Cluster
# task_definition is of type TaskDefinition
# vpc is of type Vpc

service = ecs.FargateService(self, "Service", cluster=cluster, task_definition=task_definition)

lb = elbv2.ApplicationLoadBalancer(self, "LB", vpc=vpc, internet_facing=True)
listener = lb.add_listener("Listener", port=80)
service.register_load_balancer_targets(
    container_name="web",
    container_port=80,
    new_target_group_id="ECS",
    listener=ecs.ListenerConfig.application_listener(listener,
        protocol=elbv2.ApplicationProtocol.HTTPS
    )
)

Attributes

container_name

The name of the container.

Return type

str

container_port

The port number of the container.

Only applicable when using application/network load balancers.

Default
  • Container port of the first added port mapping.

Return type

Union[int, float, None]

listener

Listener and properties for adding target group to the listener.

Return type

ListenerConfig

new_target_group_id

ID for a target group to be created.

Return type

str

protocol

The protocol used for the port mapping.

Only applicable when using application load balancers.

Default

Protocol.TCP

Return type

Optional[Protocol]