If you want to run two or more Serverless API Gateways at the same time locally you can easily do it with --port
parameter.
Basically, open two command line windows and in the first window, go to your first service directory and run:
sls offline start --port 3001
in the other window, go to your second service and run:
sls offline start --port 3002
This way you you will have two services listening on two ports (in this examples http://localhost:3001
and http://localhost:3002
).
There is one catch (at the moment) if you also use serverless-dynamodb-local plugin:
If you don't use DynamoDB plugin then you are okay and can stop reading now :)
DynamoDB plugin is using the same --port
parameter and that causes java.net.BindException: Address already in use
See this issue: https://github.com/99xt/serverless-dynamodb-local/issues/135
The workaround for this is to keep serverless-offline-local
plugin enabled in only one service (if you have two or more).
Example,
In my-service-1
you keep all dynamodb config in serverless.yaml
file and start this service with default port: sls offline start --migrate true
. In the next service, let's call it my-service-2
you remove serverless-dynamodb-local
from plugins
in serverless.yaml
(there is no need for any other changes) and then you can start the service with: sls offline start --port 3001
.
First service will start DynamoDB and the second one will be able to use it.
serverless-offline
will proxy requests tohttp://localhost:3000
by default, and this will handle requests against multiple endpoints/functions. But it sounds like you have something different going on - can you post yourserverless.yml
? I don't really know the answer to this question, as this is a very bleeding edge project, but I might be able to talk through a few things. – Execrate