11
votes

Get the following when deploying a CloudFormation stack:

The REST API doesn't contain any methods (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: d527f56e-a1e1-11e9-a0a4-af7563b2b15a)

The stack has a single Lambda triggered by an API with a single resource and method:

FailureReporting:
    Type: "AWS::ApiGateway::RestApi"
    DependsOn: "MyLambdaFunction"
    Properties:
      Name: "FailureReporting"
      FailOnWarnings: true
  FailureReportingDeployment:
    Type: AWS::ApiGateway::Deployment
    Properties:
      RestApiId:
        Ref: "FailureReporting"
      Description: "Production environment supporting version-1 of the interface."
      StageName: "v1"
  Failures:
    Type: "AWS::ApiGateway::Resource"
    Properties:
      RestApiId: !Ref "FailureReporting"
      ParentId: !GetAtt ["FailureReporting", "RootResourceId"]
      PathPart: "failures"
  FailuresMethodGet:
    Type: "AWS::ApiGateway::Method"
    Properties:
      RestApiId: !Ref "FailureReporting"
      ResourceId: !Ref "Failures"
      HttpMethod: "GET"
      AuthorizationType: "NONE"
      MethodResponses:
        - StatusCode: "200"
      Integration:
        IntegrationHttpMethod: "POST"
        Type: "AWS_PROXY"
        IntegrationResponses:
          - StatusCode: "200"
        Credentials: !GetAtt [ 3FailureReportingExecuteAPI, Arn ]
        Uri: !Sub
          - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations"
          - lambdaArn: !GetAtt [ GetFailureKeysByOrderNumber, Arn ]

I'm missing where I mucked up.

1
Curious any Events and Swagger for API.Rafee
Nope, there are no event or swagger sections.Adam

1 Answers

15
votes

Put a DependsOn the deployment resource:

  FailureReportingDeployment:
    Type: AWS::ApiGateway::Deployment
    DependsOn:
      - "FailuresMethodGet"
    Properties:
      Description: "Production environment supporting version-1 of the interface."
      RestApiId: !Ref "FailureReporting"
      StageName: "v1"

It's not intuitive. Buried in the docs you'll find the following:

If you create an AWS::ApiGateway::RestApi resource and its methods (using AWS::ApiGateway::Method) in the same template as your deployment, the deployment must depend on the RestApi's methods. To create a dependency, add a DependsOn attribute to the deployment. If you don't, AWS CloudFormation creates the deployment right after it creates the RestApi resource that doesn't contain any methods, and AWS CloudFormation encounters the following error: The REST API doesn't contain any methods.