I have two Serverless Offline "servers" which I need to run locally at same time.
So I need to change the port of one of the servers.
I run a server using Visual Studio Code debugger. The configs of the servers are in launch.json files.
How can I change the port of a Serverless Offline application so that I can run it in parallel with another Serverless Offline application using VS Code debugger?
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 .
Since you already know the basics of Serverless Framework, you must have installed the framework. Next, install the package serverless-offline from npm. 2. Add this installed plugin to your serverless project.
The serverless offline plugin for Node. js allows you to emulate AWS Lambda and API Gateway on a local machine. By using the serverless offline plugin, you can test your serverless applications without deploying them every time you make a change.
This Serverless plugin emulates AWS λ and API Gateway on your local machine to speed up your development cycles. To do so, it starts an HTTP server that handles the request's lifecycle like APIG does and invokes your handlers.
If you are using windows, update the vscode launch.json and package.json as below :
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Serverless",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"debug"
],
"outFiles": [
"${workspaceFolder}/handler.js"
],
"port": 9229,
"sourceMaps": true
}
]
}
// package.json
....
"scripts": {
"debug": "SET SLS_DEBUG=* && node --inspect %USERPROFILE%\\AppData\\Roaming\\npm\\node_modules\\serverless\\bin\\serverless offline -s dev"
}
If on linux your debug script will be:
// package.json
....
"scripts": {
"debug": "export SLS_DEBUG=* && node --inspect /usr/local/bin/serverless offline -s dev"
}
Solved by adding the following lines to the serverless.yml file:
custom:
serverless-offline: ## add this two lines
port: 4000 ## bellow "custom:" line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With