Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFormation Stack Errors with REST API Doesn't Contain Any Methods

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.

like image 904
Adam Avatar asked Jul 09 '19 02:07

Adam


People also ask

How do you troubleshoot CloudFormation stack?

Troubleshooting guideUse the CloudFormation console to view the status of your stack. In the console, you can view a list of stack events while your stack is being created, updated, or deleted. From this list, find the failure event and then view the status reason for that event.

What happens when CloudFormation stack creation fails?

If stack creation fails, go to the CloudFormation Resources list in the AWS Management Console to find the log group. Note that if stack creation fails before any instances are launched, a log group might not be created. By default, AWS deletes CloudWatch log groups if stack creation fails.

How do I rerun a failed CloudFormation stack?

In the console, select the stack set that contains the stack on which the operation failed. In the Actions menu, choose Edit StackSet details to retry creating or updating stacks. On the Specify template page, to use the same AWS CloudFormation template, keep the default option, Use current template.

How to resolve “the REST API doesn’t contain any methods” error?

The reason we get the validation error "The REST API doesn't contain any methods" in AWS CDK is because we are trying to deploy an API Gateway RestApi without setting any resources and methods. In order to solve the error, we have to define at least 1 resource with a method on the API, i.e. an endpoint /tasks with an HTTP method GET.

Why did my AWS CloudFormation stack fail?

When you create or update an AWS CloudFormation stack, your stack can fail due to invalid input parameters, unsupported resource property names, or unsupported resource property values. For input parameters, verify that the resource exists.

Why did a resource not respond to CloudFormation?

A resource didn't respond because the operation exceeded the AWS CloudFormation timeout period or an AWS service was interrupted. For service interruptions, check that the relevant AWS service is running, and then retry the stack operation.

Why is my nested stack not cleaning up from CloudFormation?

A nested stack that completed updating or rolling back but didn't receive a signal from AWS CloudFormation to start cleaning up because another nested failed to roll back is in an UPDATE_COMPLETE_CLEANUP_IN_PROGRESS or UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS state.


1 Answers

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.

like image 100
Rudy2015 Avatar answered Oct 07 '22 08:10

Rudy2015