8000 bug: API Gateway V1 REST requests breaks when path parameter validation is enabled in serverless · Issue #7842 · localstack/localstack · GitHub 10000
[go: up one dir, main page]

Skip to content
bug: API Gateway V1 REST requests breaks when path parameter validation is enabled in serverless #7842
Closed
@mickfold

Description

@mickfold

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When performing any requests with path parameters with validation enabled the following error message is returned

GET http://localhost:4566/restapis/<apigw_id>/local/_user_request_/test/world

returns

{"Type": "User", "message": "Invalid request body", "__type": "InvalidRequest"}

Expected Behavior

Path parameter validation works like AWS, i.e. validation is performed, lambda is invoked and response returned to caller.

GET http://localhost:4566/restapis/<apigw_id>/local/_user_request_/test/world

returns

"hello world"

How are you starting LocalStack?

With the localstack script

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

localstack start

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

See project in zip archive - localstack-path-parameter-test.zip. Also included below.

To deploy to localstack:

  1. yarn install
  2. npx sls deploy --stage local --region eu-west-2

This has two endpoints. The first, test, works but the second endpoint, broken-test, fails with the error Invalid request body.

It looks like the error is caused by localstack not being able to handle AWS::ApiGateway::RequestValidator correctly.

Also if you try to fix an endpoint by removing the validation, i.e. change the broken-test endpoint to:

  broken-test:
    handler: handler.test
    events:
      - http:
          path: broken-test/{value}
          method: get

Then after deploying and hitting this endpoint you get an error like

{
"__type": "InternalError",
"message": "exception while calling apigateway with unknown operation: An error occurred (NotFoundException) when calling the GetRequestValidator operation: Validator 06ce6f for API Gateway 5ajrq316ln not found"
}

serverless.yml

service: locastack-test
provider:
  name: aws
  runtime: nodejs16.x
  environment:
    NODE_ENV: dev
plugins:
  - serverless-localstack
custom:
  localstack:
    stages: [local]
    host: http://127.0.0.1
    debug: true
functions:
  test:
    handler: handler.test
    events:
      - http:
          path: test/{value}
          method: get
  broken-test:
    handler: handler.test
    events:
      - http:
          path: broken-test/{value}
          method: get
          request:
            parameters:
              paths:
                issuer: true

handler.js

exports.test = async function (event, context) {
  return {
    body: `hello ${event.pathParameters.value}`,
    headers: {},
    statusCode: 200,
  };
}

package.json

{
  "name": "localstack-test",
  "devDependencies": {    
    "serverless": "^3.28.1",
    "serverless-localstack": "^1.0.4"
  }
}

Environment

- OS: AWS Linux Workspace
- LocalStack: latest

Anything else?

localstack_logs.txt

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0