Search code examples
aws-lambdaaws-serverlessaws-samaws-sam-cli

SAM template "Invalid template property or properties [MyApi]"


I am getting the following error after running CLI command aws cloudformation deploy (after sam package)

"Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Invalid template property or properties [MyApi]"

This is the template. I cannot get information about which is the invalid property. Is this possible? Else what is wrong with this template?

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

Solution

  • There is an indentation error at MyApi. Use the following:

    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