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

部署AWS SAM 'Hello World'示例时遇「Invalid outputs property」错误求助

问题描述

按照AWS SAM官方入门步骤部署无服务器"Hello World"应用,本地运行正常,执行sam validate验证template.yaml也通过,但部署时触发以下错误:

Error: Failed to create changeset for the stack: my-app, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Template format error: Invalid outputs property : [Type, Properties].

我怀疑是template.yaml的Outputs属性有误,曾尝试手动填充${ServerlessRestApi}和${AWS::Region}但无效;也考虑过Resources > HelloWorldFunction的Type/Properties存在问题,但这部分是CLI生成未做修改,且验证工具已通过,实在找不到问题所在。

附上当前使用的template.yaml代码:

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
  my-app

  Sample SAM Template for my-app

Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello-world/
      Handler: app.lambdaHandler
      Runtime: nodejs18.x
      Architectures:
        - x86_64
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get
    Metadata:
      BuildMethod: esbuild
      BuildProperties:
        Minify: true
        Target: "es2020"
        Sourcemap: true
        EntryPoints:
          - app.ts

Outputs:
  HelloWorldApi:
    Description: "API Gateway endpoint URL for Prod stage for Hello World function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn

问题原因与修复方案

错误提示明确指向Outputs属性格式异常,但从你提供的模板来看,Outputs的写法符合标准YAML语法,问题大概率出在SAM CLI版本兼容性或模板转换过程中的bug,按以下步骤排查:

  1. 升级SAM CLI到最新版本
    旧版本SAM CLI在转换包含esbuild元数据的模板时,可能会生成格式错误的CloudFormation输出项。执行对应命令升级:

    • 若用Homebrew:brew upgrade aws-sam-cli
    • 其他系统参考官方升级逻辑执行
  2. 简化Outputs排查问题项
    先注释掉Outputs中的两个项,只保留HelloWorldApi,再尝试部署:

Outputs:
  HelloWorldApi:
    Description: "API Gateway endpoint URL for Prod stage for Hello World function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
#  HelloWorldFunction:
#    Description: "Hello World Lambda Function ARN"
#    Value: !GetAtt HelloWorldFunction.Arn
#  HelloWorldFunctionIamRole:
#    Description: "Implicit IAM Role created for Hello World function"
#    Value: !GetAtt HelloWorldFunctionRole.Arn

如果部署成功,再逐个恢复注释的输出项,找到具体触发错误的条目。比如若HelloWorldFunctionIamRole导致问题,可尝试用!Ref HelloWorldFunctionRole代替!GetAtt HelloWorldFunctionRole.Arn,或确认该隐式角色的逻辑ID是否正确。

  1. 手动打包查看转换后的模板
    执行以下命令手动打包模板,查看生成的packaged.yaml中Outputs部分是否存在异常:
sam package --template-file template.yaml --output-template-file packaged.yaml --s3-bucket your-s3-bucket-name

打开packaged.yaml检查Outputs,如果发现某个输出项被错误解析为包含Type/Properties的结构,说明是SAM转换的问题,升级CLI即可解决。

内容的提问来源于stack exchange,提问作者Matt Saunders

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 20:35:15