【问题标题】:SAM template "Invalid template property or properties [MyApi]"SAM 模板“无效的模板属性或属性 [MyApi]”
【发布时间】:2019-07-28 21:21:51
【问题描述】:

运行 CLI 命令 aws cloudformation deploy 后出现以下错误(在 sam 包之后)

“创建变更集失败:Waiter ChangeSetCreateComplete 失败:Waiter 遇到终端故障状态状态:FAILED。原因:无效的模板属性或属性 [MyApi]”

这是模板。我无法获得有关哪个是无效属性的信息。这可能吗?否则这个模板有什么问题?

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31

Resources:
  HelloFunction:
    Type: AWS::Serverless::Function
    Properties:`enter code here`
      Handler: main
      Runtime: go1.x
      Events:
        GetEvent:
          Type: Api
          Properties:
            Path: /
            Method: post
            #RestApiId: !Ref ApiGateway1

  LambdaInvokePermission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !GetAtt
        - HelloFunction
        - Arn
      Action: 'lambda:InvokeFunction'
      Principal: apigateway.amazonaws.com
      SourceAccount: !Ref 'AWS::AccountId'

MyApi:
  Type: AWS::Serverless::Api
  Properties:
    StageName: default
    EndpointConfiguration: REGIONAL
    DefinitionBody:
      swagger: "2.0"
      info:
        title: "TestAPI"
      paths:
        /:
          get:
#            parameters:
#              - name: "id"
#                in: "query"
#                required: true
#                type: "string"
#            x-amazon-apigateway-request-validator: "Validate query string parameters and\
#                \ headers"
            x-amazon-apigateway-integration:
              uri:
                Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloFunction.Arn}/invocations
              responses: {}
              httpMethod: "POST"
              type: "aws_proxy"



Outputs:
  FunctioArn:
    Value: !GetAtt  HelloFunction.Arn
    Export:
      Name: HelloFunctionArn

【问题讨论】:

    标签: aws-lambda aws-serverless aws-sam aws-sam-cli


    【解决方案1】:

    MyApi 出现缩进错误。使用以下内容:

    AWSTemplateFormatVersion: 2010-09-09
    Transform: AWS::Serverless-2016-10-31
    
    Resources:
      HelloFunction:
        Type: AWS::Serverless::Function
        Properties:`enter code here`
          Handler: main
          Runtime: go1.x
          Events:
            GetEvent:
              Type: Api
              Properties:
                Path: /
                Method: post
                #RestApiId: !Ref ApiGateway1
    
      LambdaInvokePermission:
        Type: AWS::Lambda::Permission
        Properties:
          FunctionName: !GetAtt
            - HelloFunction
            - Arn
          Action: 'lambda:InvokeFunction'
          Principal: apigateway.amazonaws.com
          SourceAccount: !Ref 'AWS::AccountId'
    
      MyApi:
        Type: AWS::Serverless::Api
        Properties:
          StageName: default
          EndpointConfiguration: REGIONAL
          DefinitionBody:
            swagger: "2.0"
            info:
              title: "TestAPI"
            paths:
              /:
                get:
      #            parameters:
      #              - name: "id"
      #                in: "query"
      #                required: true
      #                type: "string"
      #            x-amazon-apigateway-request-validator: "Validate query string parameters and\
      #                \ headers"
                  x-amazon-apigateway-integration:
                    uri:
                      Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloFunction.Arn}/invocations
                    responses: {}
                    httpMethod: "POST"
                    type: "aws_proxy"
    
    
    
    Outputs:
      FunctioArn:
        Value: !GetAtt  HelloFunction.Arn
        Export:
          Name: HelloFunctionArn
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 2019-09-24
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      相关资源
      最近更新 更多