使用CloudFormation创建栈报错“Property Type cannot be empty”求助
解决CloudFormation中Listener的"Property Type cannot be empty"错误
我一眼就揪出问题所在了——你的LoadBalancerListener资源里的DefaultActions配置格式写错了!
你现在把Type和TargetGroupArn拆成了两个独立的数组元素,但实际上每个默认动作(Default Action)都是一个单独的对象,这两个属性必须放在同一个对象里。CloudFormation找不到对应动作的Type属性,自然就抛出"Property Type cannot be empty"的错误了。
错误的配置片段
DefaultActions: - Type: forward - TargetGroupArn: !Ref TargetGroup
修正后的正确配置
把这两个属性合并到同一个数组项里:
DefaultActions: - Type: forward TargetGroupArn: !Ref TargetGroup
完整修正后的模板代码
AWSTemplateFormatVersion: 2010-09-09 Description: Template for load balancer Resources: DayOne: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Scheme: internet-facing SecurityGroups: - sg-055ea833725644075 Subnets: - subnet-0d7b9bf57973e6b78 - subnet-0186890795288d48a LoadBalancerListener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: DefaultActions: - Type: forward TargetGroupArn: !Ref TargetGroup LoadBalancerArn: !Ref DayOne Port: 80 Protocol: "HTTP" TargetGroup: DependsOn: "DayOne" Type: AWS::ElasticLoadBalancingV2::TargetGroup Properties: TargetType: "instance" Name: "DayOneTarget" Port: 80 Protocol: "HTTP" VpcId: "vpc-0f98d22c9291e3c0c" HealthyThresholdCount: 2 HealthCheckTimeoutSeconds: 10 HealthCheckIntervalSeconds: 30
额外补充说明
- 每个默认动作对象必须包含
Type属性,不同的Type对应不同的必填属性:比如forward类型需要搭配TargetGroupArn,redirect类型则需要配置RedirectConfig等。 - 之前单独部署负载均衡器和目标组没问题,是因为那部分配置本身没有语法错误,添加Listener后因为格式错误才触发了CloudFormation的验证失败。
内容的提问来源于stack exchange,提问作者Nícolas Thiesen
相关产品推荐
相关产品推荐

