Search code examples
serverlessserverless-frameworkaws-serverless

How to avoid dev path when deploying to AWS with serverless locally?


When I deploy my api to AWS with serverless ($ serverless deploy), then there is always the stage added to the api URLs, for example:

foo.execute-api.eu-central-1.amazonaws.com/dev/v1/myfunc

Same thing happens when I run this locally ($ serverless offline):

localhost/dev/v1/myfunc

This is fine when deploying to AWS but for localhost I do not want this.

Question: Is there a way to remove the dev part in the url for localhost only so that the url looks like this?:

localhost/v1/myfunc

I already tried to remove the stage setting in serverless.yml but the default seems to be dev, so it doesn't matter if I specify the stage there or not.

service: my-service
frameworkVersion: "3"

provider:
  name: aws
  runtime: nodejs16.x
  stage: dev
  region: eu-central-1
  apiGateway:
    apiKeys:
      - name: my-apikey
        value: ${ssm:my-apikey}

functions:
  myfunc:
    handler: src/v1/myfunc/index.get
    events:
      - http:
          path: /v1/myfunc
          method: get
          private: true

plugins:
  - serverless-esbuild
  - serverless-offline
  - serverless-dotenv-plugin

Solution

  • The solution was to use --noPrependStageInUrl like this:

    $ serverless offline --noPrependStageInUrl