aws-cdk-lib.aws_ecs.EcsTarget

interface EcsTarget

LanguageType name
.NETAmazon.CDK.AWS.ECS.EcsTarget
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsecs#EcsTarget
Javasoftware.amazon.awscdk.services.ecs.EcsTarget
Pythonaws_cdk.aws_ecs.EcsTarget
TypeScript (source)aws-cdk-lib » aws_ecs » EcsTarget

Example

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

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

NameTypeDescription
containerNamestringThe name of the container.
listenerListenerConfigListener and properties for adding target group to the listener.
newTargetGroupIdstringID for a target group to be created.
containerPort?numberThe port number of the container.
protocol?ProtocolThe protocol used for the port mapping.

containerName

Type: string

The name of the container.


listener

Type: ListenerConfig

Listener and properties for adding target group to the listener.


newTargetGroupId

Type: string

ID for a target group to be created.


containerPort?

Type: number (optional, default: Container port of the first added port mapping.)

The port number of the container.

Only applicable when using application/network load balancers.


protocol?

Type: Protocol (optional, default: Protocol.TCP)

The protocol used for the port mapping.

Only applicable when using application load balancers.