# EcsTarget

- Source: [`aws-ecs/lib/base/base-service.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts#L202)

## Example

```ts
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
declare const vpc: ec2.Vpc;
const service = new ecs.FargateService(this, 'Service', { cluster, taskDefinition, minHealthyPercent: 100 });

const lb = new elbv2.ApplicationLoadBalancer(this, 'LB', { vpc, internetFacing: true });
const listener = lb.addListener('Listener', { port: 80 });
service.registerLoadBalancerTargets(
  {
    containerName: 'web',
    containerPort: 80,
    newTargetGroupId: 'ECS',
    listener: ecs.ListenerConfig.applicationListener(listener, {
      protocol: elbv2.ApplicationProtocol.HTTPS
    }),
  },
);
```

## Properties

- `containerName`: string (required) — The name of the container.

- `containerPort`: number — The port number of the container.

  **Default:** Container port of the first added port mapping.

  Only applicable when using application/network load balancers.

- `listener`: [ListenerConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ListenerConfig.html) (required) — Listener and properties for adding target group to the listener.

- `newTargetGroupId`: string (required) — ID for a target group to be created.

- `protocol`: [Protocol](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.Protocol.html) = Protocol.TCP — The protocol used for the port mapping.

  Only applicable when using application load balancers.
