You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CloudFormation输出Target Group ARN报错,求正确配置方法

问题解决:CloudFormation输出Target Group ARN报错

错误原因

你的模板存在两个核心结构问题:

  1. 缺少顶层Resources节点,资源直接定义在根层级,不符合CloudFormation模板结构规范
  2. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 06:32:43