0

I wanted to make a lambda available at dev-api.example.com/auth/*. The lambda will act like an auth service. So it will have urls like

  • dev-api.example.com/auth/register
  • dev-api.example.com/auth/login
  • and more ...

Like wise more lambdas will be hooked to single ApiGateway.

With that design decision, I wrote following serverless.yml file.

// serverless.yml
...
custom:
  customDomain:
    domainName: dev-api.example.com
    stage: prod
    basePath: ''
...

functions:
  auth:
    handler: src/index.handler
    events:
      - http:
          method: ANY
          path: /{auth+}

It does not seem to work. Whenever I visit dev-api.example.com/auth/register it returns Not Found error.

2 Answers 2

1

AWS API Gateway only accepts {proxy+} syntax (Link), then I think serverless fw just support {proxy+} and {any+}.

If you want to just create a function to handle 2 api endpoint, in this case, the endpoints are

POST /auth/register (I think so)

POST /auth/login

Then you have setting in serverless.yml like

...
functions:
  auth:
    handler: src/index.handler
    events:
      - http:
          method: ANY
          path: auth/{any+} # this matches any path, the token 'any' doesn't mean anything special
...
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks @hoangdv , your suggestion almost fixed the problem.

The issue was with path. It should have been path: auth/{proxy+} instead of path: /{auth+}

functions:
  auth:
    handler: src/index.handler
    events:
      - http:
          method: ANY
          path: auth/{proxy+}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.