class AlbTarget
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.ElasticLoadBalancingV2.Targets.AlbTarget |
Java | software.amazon.awscdk.services.elasticloadbalancingv2.targets.AlbTarget |
Python | aws_cdk.aws_elasticloadbalancingv2_targets.AlbTarget |
TypeScript (source) | @aws-cdk/aws-elasticloadbalancingv2-targets » AlbTarget |
Implements
INetwork
Extends
Alb
A single Application Load Balancer as the target for load balancing.
Example
import * as targets from '@aws-cdk/aws-elasticloadbalancingv2-targets';
import * as ecs from '@aws-cdk/aws-ecs';
import * as patterns from '@aws-cdk/aws-ecs-patterns';
declare const vpc: ec2.Vpc;
const task = new ecs.FargateTaskDefinition(this, 'Task', { cpu: 256, memoryLimitMiB: 512 });
task.addContainer('nginx', {
image: ecs.ContainerImage.fromRegistry('public.ecr.aws/nginx/nginx:latest'),
portMappings: [{ containerPort: 80 }],
});
const svc = new patterns.ApplicationLoadBalancedFargateService(this, 'Service', {
vpc,
taskDefinition: task,
publicLoadBalancer: false,
});
const nlb = new elbv2.NetworkLoadBalancer(this, 'Nlb', {
vpc,
crossZoneEnabled: true,
internetFacing: true,
});
const listener = nlb.addListener('listener', { port: 80 });
listener.addTargets('Targets', {
targets: [new targets.AlbTarget(svc.loadBalancer, 80)],
port: 80,
});
new CfnOutput(this, 'NlbEndpoint', { value: `http://${nlb.loadBalancerDnsName}`})
Initializer
new AlbTarget(alb: ApplicationLoadBalancer, port: number)
Parameters
- alb
Application
— The application load balancer to load balance to.Load Balancer - port
number
— The port on which the target is listening.
Methods
Name | Description |
---|---|
attach | Register this alb target with a load balancer. |
ToNetworkTargetGroup(targetGroup)
attachpublic attachToNetworkTargetGroup(targetGroup: INetworkTargetGroup): LoadBalancerTargetProps
Parameters
- targetGroup
INetwork
Target Group
Returns
Register this alb target with a load balancer.
Don't call this, it is called automatically when you add the target to a load balancer.