在 Cloudformation 中创建 Application Load Balancer 时出错...XXXXX 必须采用 ARN 格式
Error while creating Application Load Balancer in Cloudformation... XXXXX must be in ARN format
使用 AWS CloudFormation 服务,我尝试在 2 个 EC2 实例上创建应用程序弹性负载均衡器,但在创建侦听器 [AWS::ElasticLoadBalancingV2::Listener] 时出现错误,如下所示:
"AELB-ElasticLoadBa-XDTNTTXRZMC8' must be in ARN format (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Request ID: 9b18bb79-9e58-11e8-9b70-c9b2be714e80)"
我参考了 aws 代码模板并添加了下面的代码,我是否遗漏了什么?
ElasticLoadBalancer:
Type: 'AWS::ElasticLoadBalancing::LoadBalancer'
Properties:
Instances: [!Ref 'webServer1', !Ref 'webServer2']
CrossZone: 'true'
Listeners:
- LoadBalancerPort: '80'
InstancePort: '80'
Protocol: HTTP
Subnets:
- !Ref pubSubnet
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
HealthCheck:
Target: HTTP:80/
HealthyThreshold: '3'
UnhealthyThreshold: '5'
Interval: '30'
Timeout: '5'
TargetGroupService1:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
Name:
'Fn::Join':
- '-'
- - Ref: 'AWS::StackName'
- 'TargetGroupService1'
Port: 10
Protocol: HTTP
#HealthCheckPath: /service1
Targets:
- Id:
Ref: webServer1
Port: 80
VpcId: !Ref myDemoVPC
TargetGroupService2:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
Name:
'Fn::Join':
- '-'
- - Ref: 'AWS::StackName'
- 'TargetGroupService2'
Port: 10
Protocol: HTTP
#HealthCheckPath: /service2
Targets:
- Id:
Ref: webServer2
Port: 80
VpcId: !Ref myDemoVPC
Listener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroupService1
LoadBalancerArn: !Ref ElasticLoadBalancer
Port: '80'
Protocol: HTTP
ListenerRuleService1:
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref TargetGroupService1
Conditions:
- Field: path-pattern
Values:
- "/service1"
ListenerArn: !Ref Listener
Priority: 1
ListenerRuleService2:
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref TargetGroupService2
Conditions:
- Field: path-pattern
Values:
- "/service2"
ListenerArn: !Ref Listener
Priority: 2
您使用了错误的 cloudformation 资源。应用程序负载均衡器的 Type
是 AWS::ElasticLoadBalancingV2::LoadBalancer
。注意 V2
。您正在使用的那个创建了一个经典的负载均衡器。
您收到的错误是由于经典 LB 和应用程序 LB 之间 Ref
函数的 return 值不同所致。
当您指定:
LoadBalancerArn: !Ref ElasticLoadBalancer
Ref
Classic LB returns 资源名称(AELB-ElasticLoadBa-XDTNTTXRZMC8)而 Ref
ALB returns 资源 Arn 是什么 V2听众期望 LoadBalancerArn
属性。
将逻辑名称为 ElasticLoadBalancer
的资源替换为具有描述的适当属性的 V2 负载平衡器 here 应该可以解决您的问题。
使用 AWS CloudFormation 服务,我尝试在 2 个 EC2 实例上创建应用程序弹性负载均衡器,但在创建侦听器 [AWS::ElasticLoadBalancingV2::Listener] 时出现错误,如下所示:
"AELB-ElasticLoadBa-XDTNTTXRZMC8' must be in ARN format (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Request ID: 9b18bb79-9e58-11e8-9b70-c9b2be714e80)"
我参考了 aws 代码模板并添加了下面的代码,我是否遗漏了什么?
ElasticLoadBalancer:
Type: 'AWS::ElasticLoadBalancing::LoadBalancer'
Properties:
Instances: [!Ref 'webServer1', !Ref 'webServer2']
CrossZone: 'true'
Listeners:
- LoadBalancerPort: '80'
InstancePort: '80'
Protocol: HTTP
Subnets:
- !Ref pubSubnet
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
HealthCheck:
Target: HTTP:80/
HealthyThreshold: '3'
UnhealthyThreshold: '5'
Interval: '30'
Timeout: '5'
TargetGroupService1:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
Name:
'Fn::Join':
- '-'
- - Ref: 'AWS::StackName'
- 'TargetGroupService1'
Port: 10
Protocol: HTTP
#HealthCheckPath: /service1
Targets:
- Id:
Ref: webServer1
Port: 80
VpcId: !Ref myDemoVPC
TargetGroupService2:
Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
Properties:
Name:
'Fn::Join':
- '-'
- - Ref: 'AWS::StackName'
- 'TargetGroupService2'
Port: 10
Protocol: HTTP
#HealthCheckPath: /service2
Targets:
- Id:
Ref: webServer2
Port: 80
VpcId: !Ref myDemoVPC
Listener:
Type: 'AWS::ElasticLoadBalancingV2::Listener'
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroupService1
LoadBalancerArn: !Ref ElasticLoadBalancer
Port: '80'
Protocol: HTTP
ListenerRuleService1:
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref TargetGroupService1
Conditions:
- Field: path-pattern
Values:
- "/service1"
ListenerArn: !Ref Listener
Priority: 1
ListenerRuleService2:
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref TargetGroupService2
Conditions:
- Field: path-pattern
Values:
- "/service2"
ListenerArn: !Ref Listener
Priority: 2
您使用了错误的 cloudformation 资源。应用程序负载均衡器的 Type
是 AWS::ElasticLoadBalancingV2::LoadBalancer
。注意 V2
。您正在使用的那个创建了一个经典的负载均衡器。
您收到的错误是由于经典 LB 和应用程序 LB 之间 Ref
函数的 return 值不同所致。
当您指定:
LoadBalancerArn: !Ref ElasticLoadBalancer
Ref
Classic LB returns 资源名称(AELB-ElasticLoadBa-XDTNTTXRZMC8)而 Ref
ALB returns 资源 Arn 是什么 V2听众期望 LoadBalancerArn
属性。
将逻辑名称为 ElasticLoadBalancer
的资源替换为具有描述的适当属性的 V2 负载平衡器 here 应该可以解决您的问题。