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

AWS sam deploy失败提示ChangeSetCreateComplete超过最大尝试次数求助

你遇到的KeyError: 'StatusReason'是1.26.0版本AWS SAM CLI的已知缺陷,当CloudFormation模板存在语法/配置错误导致变更集创建失败时,该版本CLI无法正常解析返回的错误信息,会直接抛出该异常。你模板中的DynamoDB配置存在三处错误,修复后即可正常部署:

  • 资源类型拼写错误:DynamoDB表的资源类型应为AWS::DynamoDB::Table,你当前配置少了一个冒号,写成了AWS::DynamoDB:Table
  • 全局二级索引格式错误:GlobalSecondaryIndexes是数组类型,支持配置多个索引,你当前直接写了单个索引对象,需要在索引配置前加短横线标识为列表项
  • 权限配置位置错误:Policies是AWS::Serverless::Function类型资源的属性,用于为Lambda函数配置权限,你错误写在了DynamoDB表的属性下。如果需要让HelloWorldFunction拥有该DynamoDB表的读写权限,需要把这段Policies配置移动到HelloWorldFunction的Properties节点下。

修正后的关键配置参考

# 修正后的DynamoDB表配置
MyTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: my-table
    AttributeDefinitions:
      - AttributeName: note_id
        AttributeType: S
      - AttributeName: upload_uri
        AttributeType: S
    KeySchema:
      - AttributeName: note_id
        KeyType: HASH
    GlobalSecondaryIndexes:
      - IndexName: "upload_uri"
        KeySchema:
          - AttributeName: "upload_uri"
            KeyType: "HASH"
        Projection:
          ProjectionType: "ALL"
        ProvisionedThroughput: 
          ReadCapacityUnits: 5
          WriteCapacityUnits: 5
    ProvisionedThroughput: 
      ReadCapacityUnits: 5
      WriteCapacityUnits: 5
# 修正后的Lambda函数配置
HelloWorldFunction:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: hello_world/
    Handler: app.lambda_handler
    Runtime: python3.8
    Policies:
      - DynamoDBCrudPolicy:
          TableName: !Ref MyTable
    Events:
      HelloWorld:
        Type: Api
        Properties:
          Path: /hello
          Method: get

额外建议:可以升级AWS SAM CLI到最新稳定版本,后续模板出现错误时可以直接看到具体的配置错误提示,不会再出现无意义的KeyError报错。

内容的提问来源于stack exchange,提问作者Vishnu Chopra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.10 19:54:01