0
votes

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

2 Answers

1
votes

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
...
0
votes

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+}