Debuging Serverless with VS code

can anyone give a solution

I’ve replied to your Stack Overflow post. Hopefully that will help you.

Hi @buggy
How do I pass the params for a API endpoint? for example I have an endpoint:

http://localhost:3000/v2/user/login

which takes body of username password

{
	"username" : {{admin_username}},
	"password" : {{admin_password}}
}

but when I am using the data arg in vs-code

{
            "type": "node",
            "request": "launch",
            "name": "Launch Serverless Offline",
            "program": "${workspaceRoot}/node_modules/.bin/sls",
            "args": [
                "invoke",
                "local",
                "-f",
                "manageUser",
                "--data",
                "{\"username\" : \"admin\", \"password\" : \"apasswordhaha\"}"
            ]
        }

the event object get the value
{\"username\" : \"admin\", \"password\" : \"apasswordhaha\"}

when calling the endpoint thru postman, I get the value of event object as
"body":"{\n\t\"username\" : admin,\n\t\"password\" : apasswordhaha\n}"

Is there a way that I can pass the param in vscode in the same fashion as postman? Any help is greatly appreciated.

When you’re using postman you’re sending a request to the API Gateway, not Lambda. The API Gateway then creates an event which is used when invoking Lambda. Without the API Gateway you just need to generate that event yourself. If the only attribute you’re accessing from the event is the body then you’ll need to pass something like:

"{\"body\":\"{\\\"username\\\":\\\"admin\\\",\\\"password\\\":\\\"apasswordhaha\\\"}\"}"
1 Like

wow that worked like a charm! Thank you @buggy