localstack / serverless-localstack

⚡ Serverless plugin for running against LocalStack
511 stars 82 forks source link

Getting 'The REST API doesn't contain any methods' with AWS::Serverless::API and DefinitionUri #160

Closed danw-mpl closed 2 years ago

danw-mpl commented 2 years ago

Hello, I'm unable to deploy a AWS::Serverless::API when it's using a DefinitionUri.

The debug output contains:

localstack_main    | 2021-08-26T10:57:12:DEBUG:localstack.utils.cloudformation.template_deployer: Request for resource type "ApiGateway::Deployment" in region eu-west-1: create_deployment {'restApiId': 'mug8z1ckmh', 'stageName': 'Stage', 'description': 'RestApi deployment id: b035b55b77bd9e21a76f54317e3b330689fe3bd7'}
localstack_main    | 2021-08-26T10:57:12:DEBUG:localstack.services.edge: IN(apigateway): "POST /restapis/mug8z1ckmh/deployments" - headers: {'Remote-Addr': '127.0.0.1', 'Host': 'localhost:4566', 'Accept-Encoding': 'identity', 'User-Agent': 'Boto3/1.18.27 Python/3.7.10 Linux/5.4.72-microsoft-standard-WSL2 Botocore/1.21.27', 'Accept': 'application/json', 'X-Amz-Date': '20210826T105712Z', 'Authorization': 'AWS4-HMAC-SHA256 Credential=__internal_call__/20210826/eu-west-1/apigateway/aws4_request, SignedHeaders=accept;host;x-amz-date, Signature=78cfe4b50cecdfedd145d8adfb62277f643d72d6640ded9652129b76184efd68', 'Content-Length': '104', 'X-Forwarded-For': '127.0.0.1, localhost:4566', 'x-localstack-edge': 'http://localhost:4566'} - data: b'{"stageName": "Stage", "description": "RestApi deployment id: b035b55b77bd9e21a76f54317e3b330689fe3bd7"}'
localstack_main    | 2021-08-26T10:57:12:DEBUG:localstack.services.edge: OUT(apigateway): "POST /restapis/mug8z1ckmh/deployments" - status: 400 - response headers: {'server': 'amazon.com', 'X-Amzn-Errortype': 'BadRequestException', 'Content-Type': 'text/html; charset=utf-8', 'Content-Length': '88', 'Access-Control-Allow-Origin': '*', 'Date': 'Thu, 26 Aug 2021 10:57:12 GMT', 'Access-Control-Allow-Methods': 'HEAD,GET,PUT,POST,DELETE,OPTIONS,PATCH', 'Access-Control-Allow-Headers': 'authorization,content-type,content-length,content-md5,cache-control,x-amz-content-sha256,x-amz-date,x-amz-security-token,x-amz-user-agent,x-amz-target,x-amz-acl,x-amz-version-id,x-localstack-target,x-amz-tagging,amz-sdk-invocation-id,amz-sdk-request', 'Access-Control-Expose-Headers': 'x-amz-version-id'} - response: b'{"__type": "BadRequestException", "message": "The REST API doesn\'t contain any methods"}'
localstack_main    | 2021-08-26T10:57:12:WARNING:localstack.utils.cloudformation.template_deployer: Error calling <bound method ClientCreator._create_api_method.<locals>._api_call of <botocore.client.APIGateway object at 0x7f405293c750>> with params: {'restApiId': 'mug8z1ckmh', 'stageName': 'Stage', 'description': 'RestApi deployment id: b035b55b77bd9e21a76f54317e3b330689fe3bd7'} for resource: {'Type': 'AWS::ApiGateway::Deployment', 'LogicalResourceId': 'MyAPIDeploymentb035b55b77', 'Properties': {'Description': 'RestApi deployment id: b035b55b77bd9e21a76f54317e3b330689fe3bd7', 'RestApiId': 'mug8z1ckmh', 'StageName': 'Stage'}, '_state_': {}}
localstack_main    | 2021-08-26T10:57:12:DEBUG:localstack.utils.cloudformation.template_deployer: Error applying changes for CloudFormation stack "MyServiceStack": An error occurred (BadRequestException) when calling the CreateDeployment operation: The REST API doesn't contain any methods Traceback (most recent call last):
localstack_main    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 2138, in _run
localstack_main    |     self.do_apply_changes_in_loop(changes, stack, stack_name)
localstack_main    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 2209, in do_apply_changes_in_loop
localstack_main    |     self.apply_change(change, stack, new_resources, stack_name=stack_name)
localstack_main    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 2273, in apply_change
localstack_main    |     result = deploy_resource(resource_id, new_resources, stack_name)
localstack_main    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1048, in deploy_resource
localstack_main    |     return execute_resource_action(resource_id, resources, stack_name, ACTION_CREATE)
localstack_main    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1163, in execute_resource_action
localstack_main    |     resource_id, resources, resource_type, func, stack_name, action_name
localstack_main    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1322, in configure_resource_via_sdk
localstack_main    |     raise e
localstack_main    |   File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1310, in configure_resource_via_sdk
localstack_main    |     result = function(**params)
localstack_main    |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/botocore/client.py", line 386, in _api_call
localstack_main    |     return self._make_api_call(operation_name, kwargs)
localstack_main    |   File "/opt/code/localstack/.venv/lib/python3.7/site-packages/botocore/client.py", line 705, in _make_api_call
localstack_main    |     raise error_class(parsed_response, operation_name)
localstack_main    | botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the CreateDeployment operation: The REST API doesn't contain any methods

Reproduce

SAM Template

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

Description: "Deployment of My Service"

Resources:
  MyServiceAPI:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      Name: MyService
      EndpointConfiguration: REGIONAL
      DefinitionUri: ./MyServiceTemplate.yaml

Definition file

openapi: 3.0.0
info:
  title: Redacted
  description: Redacted
  version: '0.1'
paths:
  /:
    get:
      summary: Redacted
      description: Redacted
      tags:
        - list
      parameters:
        - in: query
          name: search
          schema:
            type: string
          required: false
          description: search options `name:{value}`
        - in: query
          name: next
          schema:
            type: 'string'
          required: false
          description: Token for next page of results
        - in: query
          name: previous
          schema:
            type: 'string'
          required: false
          description: Token for previous page of results
      responses:
        '200':
          description: Success. Returns a List of all Indices.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Indices'
{...}
whummer commented 2 years ago

Thanks for reporting @danw-mpl . Can you please also share your serverless.yml configuration file as well as the exact command you're using to deploy the application, so we can replicate this use case end-to-end? Thanks!

danw-mpl commented 2 years ago

Ha, just noticed I put this in the wrong project. I'm using SAM, not Serverless. I'll move it over to the localstack project.