【问题标题】:Trying to create a stack in cloud formation using SAM and getting an error message尝试使用 SAM 在云形成中创建堆栈并收到错误消息
【发布时间】:2021-10-04 13:55:51
【问题描述】:

当我尝试使用 SAM 部署堆栈时,我收到以下错误消息。

“无法为堆栈创建变更集:测试,例如:Waiter ChangeSetCreateComplete 失败:Waiter 遇到终端故障状态:对于表达式“状态”,我们匹配预期路径:“FAILED”状态:FAILED。原因:无效的模板资源属性'KeySchema'"

我正在尝试创建一个 API 网关,该网关连接到将与 DynamoDB 表交互的 Lambda 函数。根据文档https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-dynamodb.html

,我的 YAML 模板文件有效,并且 KeySchema 似乎是有效的资源属性

我的 Yaml 文件如下所示

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: "Stack for DynamoDB, Lambda and APIGateway"
Resources:
  CounterFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: Backend/
      Handler: lambda.lambda_handler
      Runtime: python3.8
        
      Events:
        VisitorData:
          Type: Api
          Properties:
           Path: /Counter
           Method: get
    
  Visitors:
    Type: AWS::DyanmoDB::Table
    Properties:
      AttributeDefinitions:
          -
            AttributeName: "ID"
            AttributeType: "N"
          -
            AttributeName: "Counter"
            AttributeType: "N"
      KeySchema:
        - AttributeName: "ID"
          KeyType: "HASH"
                
      ProvisionedThroughput:
            ReadCapacityUnits: 5
            WriteCapacityUnits: 5

Outputs:
  VisitorDataApi:
    Description: "API Gateway endpoint URL for Prod stage for Counter Function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  CounterFunction:
    Description: "Counter Function lambda ARN"
    Value: !GetAtt CounterFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Counter Function"
    Value: !GetAtt  Lambda-Get-Function-role-40isam1j
  Visitors Table:
    Description: "Visitor table ARN"
    Value: !GetAtt "Visitors.ARN"

感谢您提供任何反馈并了解错误消息试图告诉我的内容。

【问题讨论】:

    标签: amazon-web-services yaml amazon-cloudformation aws-sam


    【解决方案1】:

    我理解我的代码中的错误。 @Marcin 提出了一些好的观点,但为什么什么也没发生是因为它每次构建它时都会创建一个名为 template.yml 的新文件。我的原始文件名为 Infrastructure.yml,但更新只是在一个新文件中创建,感谢您的帮助

    【讨论】:

      【解决方案2】:

      应该是:

      Type: AWS::DynamoDB::Table
      

      不是:

      Type: AWS::DyanmoDB::Table
      

      【讨论】:

      • 我切换它并重建文件,但仍然弹出相同的错误
      • @Noahharris 你必须从你的属性中删除 Counter 。唯一的属性是 ID。你的情况没有别的。
      • 我得到同样的错误,关于关键模式是一个无效的资源属性@Marcin
      • @Noahharris 你能更新你的代码吗?改动后的现在怎么样了?
      猜你喜欢
      • 2022-11-30
      • 2021-12-18
      • 2021-09-11
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 2014-09-24
      • 1970-01-01
      相关资源
      最近更新 更多