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

ExampleMetadata:

infused

Example:

# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# vpc: ec2.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.

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.

listener

Listener and properties for adding target group to the listener.

new_target_group_id

ID for a target group to be created.

protocol

The protocol used for the port mapping.

Only applicable when using application load balancers.

Default:

Protocol.TCP