- Edit
serverless.yml, thehandlerpath should be from the root folder (notdist/**/your_handler.mainor from any directory with compiled files), for instance:... my_function: handler: handlers/my_function.main ...
- Edit
serverless.ymladdingserverless-plugin-typescriptto the plugin section:plugins: - serverless-plugin-typescript ...
- Install the plugin and some other NPM dependencies:
$ npm install --save-dev typescript $ npm install --save-dev serverless-plugin-typescript - Edit your
launch.jsonwith something like this:{ "version": "0.2.0", " configurations": [ { "type": "node", "request": "launch", "name": "Whatever you want", "program": "${workspaceFolder}/node_modules/serverless/bin/serverless", "args": [ "invoke", "local", "--function", "my_function", "--path", "mocks/my_function.json" ], "sourceMaps": true, "preLaunchTask": "tsc: build - tsconfig.cjs.json", "runtimeArgs": ["--lazy"], "protocol": "inspector", "runtimeExecutable": "node", "env": { }, } ] } - Check the VSCode debug console to see if it is working.
-
Adding
"outFiles": ["${workspaceFolder}/dist/**/*.js"]to thelaunch.jsonavoid errors likeCould not read source map for file://..../node_modules/typescript/lib/typescript.js.map'but it probably won't hit breakpoints. -
More information : https://enrico-portolan.medium.com/debugging-typescript-aws-lambda-with-vscode-and-serverless-967f2a201fab.
-
To debug without mocks for instance to invoke endpoints from Postman, edit your
launch.jsonwith something like this:{ "version": "0.2.0", " configurations": [ { "type": "node", "request": "launch", "name": "Whatever you want", "program": "${workspaceFolder}/node_modules/serverless/bin/serverless", "args": ["offline"], "sourceMaps": true, "preLaunchTask": "tsc: build - tsconfig.cjs.json", "runtimeArgs": ["--lazy"], "protocol": "inspector", "runtimeExecutable": "node", "env": { }, } ] }and remove
serverless-plugin-typescriptfrom theserverless.yml(also the change all handlers path on theserverless.ymlas mentioned before)