首页 > 解决方案 > 尝试使用 SAM 在云形成中创建堆栈并收到错误消息

问题描述

当我尝试使用 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-servicesyamlamazon-cloudformationaws-sam

解决方案


它应该是:

Type: AWS::DynamoDB::Table

不是:

Type: AWS::DyanmoDB::Table

推荐阅读