How can I specify an input for a locally debugged lambda serverless function in VSCODE

208 Views Asked by At

I have seen lots of answer of how to debug a lambda function offline in vscode and I have got that working, to the extent I can set breakpoint and step through it.

However I am unsure how to specify the payload input for the lambda function for testing.

{
    "configurations": [
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "Downloads:charge.handler (nodejs10.x)",
            "invokeTarget": {
                "target": "code",
                "projectRoot": "",
                "lambdaHandler": "charge.handler"
            },
            "lambda": {
                "runtime": "nodejs10.x",
                "payload": {},
                "environmentVariables": {}
            }
        }
    ]
}

It seems whatever I put into the payload json field, I only ever see an empty param object when my lambda function runs. I also have an ssm key saved on the aws server. Will that automatically be available to my locally debugged lambda function which I have setup with with SAM CLI, Docker and AWS CLI?

Any help would be greatly appreciated.

Thanks, Greg

1

There are 1 best solutions below

0
On

Okay so I wasn't specifying the payload properly.

Should be:

"payload": { "json": { "body": {
                "item1": 1, "item2": 2, ...
           }}}