Skip to content

bug: SAM REST API doesn't contain any methods #4543

Closed
@ghost

Description

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Trying to deploy a AWS::Serverless::Api or AWS::Serverless::HttpApi with a DefinitionBody or DefinitionUri results in a deploy failure.

Debug log shown below. Important to note the SAM CLI seems to retry the POST and never ends - shown in the log.

2021-09-06T08:13:44:DEBUG:localstack.utils.cloudformation.template_deployer: Handling "Add" for resource "MyServiceAPIDeploymentaba98bc031" (1/2) type "AWS::ApiGateway::Deployment" in loop iteration 1
2021-09-06 08:13:44,981:API: 127.0.0.1 - - [06/Sep/2021 08:13:44] "GET /restapis HTTP/1.1" 200 -
2021-09-06T08:13:44:DEBUG:localstack.utils.cloudformation.template_deployer: Running action "create" for resource type "ApiGateway::Deployment" id "MyServiceAPIDeploymentaba98bc031"
2021-09-06T08:13:44:DEBUG:localstack.utils.cloudformation.template_deployer: Request for resource type "ApiGateway::Deployment" in region eu-west-1: create_deployment {'restApiId': 'g8sztb5ds7', 'stageName': 'Stage', 'description': 'RestApi deployment id: aba98bc0318b247b1f4373c5bac91ac959a8ff4f'}
2021-09-06 08:13:44,994:API: 127.0.0.1 - - [06/Sep/2021 08:13:44] "POST /restapis/g8sztb5ds7/deployments HTTP/1.1" 400 -
2021-09-06T08:13:44:WARNING:localstack.utils.cloudformation.template_deployer: Error calling <bound method ClientCreator._create_api_method.<locals>._api_call of <botocore.client.APIGateway object at 0x7fe6c7296d50>> with params: {'restApiId': 'g8sztb5ds7', 'stageName': 'Stage', 'description': 'RestApi deployment id: aba98bc0318b247b1f4373c5bac91ac959a8ff4f'} for resource: {'Type': 'AWS::ApiGateway::Deployment', 'LogicalResourceId': 'MyServiceAPIDeploymentaba98bc031', 'Properties': {'Description': 'RestApi deployment id: aba98bc0318b247b1f4373c5bac91ac959a8ff4f', 'RestApiId': 'g8sztb5ds7', 'StageName': 'Stage'}, '_state_': {}}
2021-09-06T08:13:44:DEBUG:localstack.utils.cloudformation.template_deployer: Error applying changes for CloudFormation stack "MyStack": An error occurred (BadRequestException) when calling the CreateDeployment operation: The REST API doesn't contain any methods Traceback (most recent call last):
  File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 2066, in _run
    self.do_apply_changes_in_loop(changes, stack, stack_name)
  File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 2137, in do_apply_changes_in_loop
    self.apply_change(change, stack, new_resources, stack_name=stack_name)
  File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 2201, in apply_change
    result = deploy_resource(resource_id, new_resources, stack_name)
  File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1019, in deploy_resource
    return execute_resource_action(resource_id, resources, stack_name, ACTION_CREATE)
  File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1134, in execute_resource_action
    resource_id, resources, resource_type, func, stack_name, action_name
  File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1293, in configure_resource_via_sdk
    raise e
  File "/opt/code/localstack/localstack/utils/cloudformation/template_deployer.py", line 1281, in configure_resource_via_sdk
    result = function(**params)
  File "/opt/code/localstack/.venv/lib/python3.7/site-packages/botocore/client.py", line 386, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/opt/code/localstack/.venv/lib/python3.7/site-packages/botocore/client.py", line 705, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the CreateDeployment operation: The REST API doesn't contain any methods

2021-09-06 08:13:45,292:API: 127.0.0.1 - - [06/Sep/2021 08:13:45] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:45,306:API: 127.0.0.1 - - [06/Sep/2021 08:13:45] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:45,827:API: 127.0.0.1 - - [06/Sep/2021 08:13:45] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:45,838:API: 127.0.0.1 - - [06/Sep/2021 08:13:45] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:46,353:API: 127.0.0.1 - - [06/Sep/2021 08:13:46] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:46,367:API: 127.0.0.1 - - [06/Sep/2021 08:13:46] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:46,889:API: 127.0.0.1 - - [06/Sep/2021 08:13:46] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:46,897:API: 127.0.0.1 - - [06/Sep/2021 08:13:46] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:47,408:API: 127.0.0.1 - - [06/Sep/2021 08:13:47] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:47,417:API: 127.0.0.1 - - [06/Sep/2021 08:13:47] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:47,931:API: 127.0.0.1 - - [06/Sep/2021 08:13:47] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:47,940:API: 127.0.0.1 - - [06/Sep/2021 08:13:47] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:48,454:API: 127.0.0.1 - - [06/Sep/2021 08:13:48] "POST / HTTP/1.1" 200 -
2021-09-06 08:13:48,470:API: 127.0.0.1 - - [06/Sep/2021 08:13:48] "POST / HTTP/1.1" 200 -

Expected Behavior

The API should deploy.

How are you starting LocalStack?

With the localstack script

Steps To Reproduce

export AWS_DEFAULT_REGION=eu-west-1
localstack --debug start
awslocal s3 mb s3://sam-bucket
samlocal build --template Infrastructure.yaml
samlocal package --template-file .aws-sam/build/template.yaml --s3-bucket sam-bucket --output-template-file Infrastructure-packaged.yaml
samlocal deploy --stack-name MyStack --template Infrastructure-packaged.yaml

Infrastructure.yaml

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

MyServiceTemplate.yaml

openapi: 3.0.0
info:
  title: simple-node-api
  description: A simple API for a guestbook application
  version: 2019-10-13
paths:
  /:
    post:
      operationId: CreateMessage
      requestBody:
        content:
          text/plain:
            schema:
              type: string
        required: true
      responses:
        "201":
          description: "Successfully created a message."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Message"
        "400":
          description: "Bad Request Exception"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BadRequestException"
        "500":
          description: "Internal Server Error"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InternalServerErrorException"
    get:
      operationId: ListMessages
      parameters:
        - name: maxItems
          in: query
          required: false
          schema:
            type: number
        - name: token
          in: query
          required: false
          schema:
            type: string
      responses:
        "200":
          description: "Successfully listed messages."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MessageList"
        "400":
          description: "Bad Request Exception"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BadRequestException"
        "500":
          description: "Internal Server Error"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InternalServerErrorException"
components:
  schemas:
    Message:
      type: object
      properties:
        message:
          type: string
        author:
          type: string
        date:
          type: string
          format: date-time
    MessageList:
      type: object
      properties:
        items: 
          type: array
          items:
            $ref: "#/components/schemas/Message"
        nextToken:
          type: string
          required:
            - items
    BadRequestException:
      type: object
      properties:
        message:
          type: string
        errorCode:
          type: string
    InternalServerErrorException:
      type: object
      properties:
        message:
          type: string
        errorCode:
          type: string

Environment

- OS: Ubuntu 20.04 on WSL2 (Win 10)
- LocalStack: 0.12.17.5
- AWS SAM: SAM CLI, version 1.23.0

Anything else?

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions