我有一些应用程序在aws中作为微服务运行。其中一些在端口80上运行,而某些在端口3000上运行。我希望ALB监听两个端口上的流量。然后,我有一个ListenRules
将流量定向到微服务。我想实现以下目标,
Resources:
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Ref EnvironmentName
Subnets: !Ref Subnets
SecurityGroups:
- !Ref SecurityGroup
Tags:
- Key: Name
Value: !Ref EnvironmentName
LoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: [80,3000] # something like this
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref DefaultTargetGroup
答案 0 :(得分:1)
应该对每个要打开的端口重复侦听器。例如:
Resources:
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Ref EnvironmentName
Subnets: !Ref Subnets
SecurityGroups:
- !Ref SecurityGroup
Tags:
- Key: Name
Value: !Ref EnvironmentName
LoadBalancerListenerA:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroupForPort80
LoadBalancerListenerB:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: 3000
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroupForPort3000
这还使您可以灵活地为每个端口设置不同的协议(例如HTTPS)或目标组。