LoadBalancerTargetOptions

class aws_cdk.aws_ecs.LoadBalancerTargetOptions(*, container_name, container_port=None, protocol=None)

Bases: object

Properties for defining an ECS target.

The port mapping for it must already have been created through addPortMapping().

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

  • 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.Ec2Service(self, "Service", cluster=cluster, task_definition=task_definition)

lb = elb.LoadBalancer(self, "LB", vpc=vpc)
lb.add_listener(external_port=80)
lb.add_target(service.load_balancer_target(
    container_name="MyContainer",
    container_port=80
))

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.

protocol

The protocol used for the port mapping.

Only applicable when using application load balancers.

Default:

Protocol.TCP