To create a target group
If you don't have a target group that you can use for the default action,
use the create-target-group command to create one now. For
examples, see Create a target group.
To add a TCP listener
Use the create-listener command, specifying the TCP protocol.
aws elbv2 create-listener \
--load-balancer-arn load-balancer-arn \
--protocol TCP \
--port 80 \
--default-actions Type=forward,TargetGroupArn=target-group-arn
To add a TCP listener with multiple target groups
Use the create-listener command, specifying the TCP protocol, target groups, and weights.
aws elbv2 create-listener \
--load-balancer-arn load-balancer-arn \
--protocol TCP \
--port 80 \
--default-actions '[{
"Type":"forward",
"ForwardConfig":{
"TargetGroups":[
{"TargetGroupArn":"target-group-1-arn","Weight":10},
{"TargetGroupArn":"target-group-2-arn","Weight":30}
]
}
}]'
To add a TLS listener
Use the create-listener command specifying the TLS protocol.
aws elbv2 create-listener \
--load-balancer-arn load-balancer-arn \
--protocol TLS \
--port 443 \
--certificates CertificateArn=certificate-arn \
--ssl-policy ELBSecurityPolicy-TLS13-1-2-Res-2021-06 \
--default-actions Type=forward,TargetGroupArn=target-group-arn
To add a UDP listener
Use the create-listener command specifying the UDP protocol.
aws elbv2 create-listener \
--load-balancer-arn load-balancer-arn \
--protocol UDP \
--port 53 \
--default-actions Type=forward,TargetGroupArn=target-group-arn
To add a QUIC listener
Use the create-listener command specifying the QUIC protocol.
aws elbv2 create-listener \
--load-balancer-arn load-balancer-arn \
--protocol QUIC \
--port 443 \
--default-actions Type=forward,TargetGroupArn=target-group-arn
To add a TCP listener
Define a resource of type AWS::ElasticLoadBalancingV2::Listener using the
TCP protocol.
Resources:
myTCPListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
LoadBalancerArn: !Ref myLoadBalancer
Protocol: TCP
Port: 80
DefaultActions:
- Type: forward
TargetGroupArn: !Ref myTargetGroup
To add a TCP listener with multiple target groups
Define a resource of type AWS::ElasticLoadBalancingV2::Listener using the
TCP protocol.
Resources:
myTCPListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
LoadBalancerArn: !Ref myLoadBalancer
Protocol: TCP
Port: 80
DefaultActions:
- Type: forward
ForwardConfig:
TargetGroups:
- TargetGroupArn: !Ref myTargetGroup1,
Weight: 10
- TargetGroupArn: !Ref myTargetGroup2,
Weight: 30
TargetGroupStickinessConfig:
Enabled: true
To add a TLS listener
Define a resource of type AWS::ElasticLoadBalancingV2::Listener using the
TLS protocol.
Resources:
myTLSListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
LoadBalancerArn: !Ref myLoadBalancer
Protocol: TLS
Port: 443
SslPolicy: "ELBSecurityPolicy-TLS13-1-2-Res-2021-06"
Certificates:
- CertificateArn: "certificate-arn"
DefaultActions:
- Type: forward
TargetGroupArn: !Ref myTargetGroup
To add a UDP listener
Define a resource of type AWS::ElasticLoadBalancingV2::Listener using the
UDP protocol.
Resources:
myUDPListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
LoadBalancerArn: !Ref myLoadBalancer
Protocol: UDP
Port: 53
DefaultActions:
- Type: forward
TargetGroupArn: !Ref myTargetGroup
To add a QUIC listener
Define a resource of type AWS::ElasticLoadBalancingV2::Listener using the
QUIC protocol.
Resources:
myQUICListener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
LoadBalancerArn: !Ref myLoadBalancer
Protocol: QUIC
Port: 443
DefaultActions:
- Type: forward
TargetGroupArn: !Ref myTargetGroup