ListenerConfig Class
Base class for configuring listener when registering targets.
| Source | aws-ecs/lib/base/base-service.ts |
|---|
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
}),
},
);
python
# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# vpc: ec2.Vpc
service = ecs.FargateService(self, "Service", cluster=cluster, task_definition=task_definition, min_healthy_percent=100)
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
)
)
java
Cluster cluster;
TaskDefinition taskDefinition;
Vpc vpc;
FargateService service = FargateService.Builder.create(this, "Service").cluster(cluster).taskDefinition(taskDefinition).minHealthyPercent(100).build();
ApplicationLoadBalancer lb = ApplicationLoadBalancer.Builder.create(this, "LB").vpc(vpc).internetFacing(true).build();
ApplicationListener listener = lb.addListener("Listener", BaseApplicationListenerProps.builder().port(80).build());
service.registerLoadBalancerTargets(EcsTarget.builder()
.containerName("web")
.containerPort(80)
.newTargetGroupId("ECS")
.listener(ListenerConfig.applicationListener(listener, AddApplicationTargetsProps.builder()
.protocol(ApplicationProtocol.HTTPS)
.build()))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;
TaskDefinition taskDefinition;
Vpc vpc;
var service = new FargateService(this, "Service", new FargateServiceProps { Cluster = cluster, TaskDefinition = taskDefinition, MinHealthyPercent = 100 });
var lb = new ApplicationLoadBalancer(this, "LB", new ApplicationLoadBalancerProps { Vpc = vpc, InternetFacing = true });
var listener = lb.AddListener("Listener", new BaseApplicationListenerProps { Port = 80 });
service.RegisterLoadBalancerTargets(new EcsTarget {
ContainerName = "web",
ContainerPort = 80,
NewTargetGroupId = "ECS",
Listener = ListenerConfig.ApplicationListener(listener, new AddApplicationTargetsProps {
Protocol = ApplicationProtocol.HTTPS
})
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster
var taskDefinition TaskDefinition
var vpc Vpc
service := ecs.NewFargateService(this, jsii.String("Service"), &FargateServiceProps{
Cluster: Cluster,
TaskDefinition: TaskDefinition,
MinHealthyPercent: jsii.Number(100),
})
lb := elbv2.NewApplicationLoadBalancer(this, jsii.String("LB"), &ApplicationLoadBalancerProps{
Vpc: Vpc,
InternetFacing: jsii.Boolean(true),
})
listener := lb.AddListener(jsii.String("Listener"), &BaseApplicationListenerProps{
Port: jsii.Number(80),
})
service.RegisterLoadBalancerTargets(&EcsTarget{
ContainerName: jsii.String("web"),
ContainerPort: jsii.Number(80),
NewTargetGroupId: jsii.String("ECS"),
Listener: ecs.ListenerConfig_ApplicationListener(listener, &AddApplicationTargetsProps{
Protocol: elbv2.ApplicationProtocol_HTTPS,
}),
})
Initializer
ts
new ListenerConfig()
python
ListenerConfig()
java
new ListenerConfig()
csharp
new ListenerConfig()
go
NewListenerConfig()
Methods
addTargets(id: string, target: LoadBalancerTargetOptions, service: BaseService): voiddef add_targets(self, id: str, target: LoadBalancerTargetOptions, service: BaseService) -> Nonepublic void addTargets(String id, LoadBalancerTargetOptions target, BaseService service)public void AddTargets(string id, LoadBalancerTargetOptions target, BaseService service)func AddTargets(Id *string, Target LoadBalancerTargetOptions, Service BaseService) #Create and attach a target group to listener.
applicationListener(listener: ApplicationListener, props?: AddApplicationTargetsProps): ListenerConfig // chainable@staticmethod def application_listener(listener: ApplicationListener, props: typing.Optional[AddApplicationTargetsProps] = None) -> ListenerConfigpublic static ListenerConfig applicationListener(ApplicationListener listener, AddApplicationTargetsProps props)public static ListenerConfig ApplicationListener(ApplicationListener listener, AddApplicationTargetsProps? props = null)func ApplicationListener(Listener ApplicationListener, Props AddApplicationTargetsProps) ListenerConfig static #Create a config for adding target group to ALB listener.
networkListener(listener: NetworkListener, props?: AddNetworkTargetsProps): ListenerConfig // chainable@staticmethod def network_listener(listener: NetworkListener, props: typing.Optional[AddNetworkTargetsProps] = None) -> ListenerConfigpublic static ListenerConfig networkListener(NetworkListener listener, AddNetworkTargetsProps props)public static ListenerConfig NetworkListener(NetworkListener listener, AddNetworkTargetsProps? props = null)func NetworkListener(Listener NetworkListener, Props AddNetworkTargetsProps) ListenerConfig static #Create a config for adding target group to NLB listener.