CloudFormation输出Target Group ARN报错,求正确配置方法
问题解决:CloudFormation输出Target Group ARN报错
错误原因
你的模板存在两个核心结构问题:
- 缺少顶层
Resources节点,资源直接定义在根层级,不符合CloudFormation模板结构规范 Outputs节点缩进错误,被识别为某个资源的属性而非顶层元素,导致系统报错“无效的资源属性”
正确模板配置
AWSTemplateFormatVersion: '2010-09-09' Resources: MyTargetGroup: Type: 'AWS::ElasticLoadBalancingV2::TargetGroup' Properties: HealthCheckEnabled: true HealthCheckIntervalSeconds: 30 HealthCheckPath: / HealthCheckProtocol: HTTP HealthCheckTimeoutSeconds: 5 HealthyThresholdCount: 5 Matcher: HttpCode: "200,302" Name: target-group-1 Protocol: HTTP Port: 80 UnhealthyThresholdCount: 2 VpcId: !ImportValue vpc-id Outputs: MyTargetGroupOutput: Value: !GetAtt MyTargetGroup.TargetGroupArn # 若需跨栈引用该ARN,可取消注释以下配置 # Export: # Name: MyTargetGroupArn
关键修正说明
- 添加
AWSTemplateFormatVersion:明确模板版本,是CloudFormation模板的标准开头 - 所有资源必须嵌套在
Resources顶层节点下:这是CloudFormation识别资源定义的唯一方式 Outputs作为顶层节点,与Resources同级:确保系统将其识别为输出配置而非资源属性
部署修正后的模板后,即可正常输出Target Group的ARN。
内容的提问来源于stack exchange,提问作者learner00
相关产品推荐
相关产品推荐

