How to change the local payload when invoking a lambda in cloud9 IDE?

305 Views Asked by At

I'm developing in AWS Cloud9, and have a basic "Hello, World" API set up using Lambda.

Now I would like to iterate so that the API can accept parameters. Cloud9 used to have a convenient UI for modifying the payload when running "local" (in the IDE, without deploy). But I can't find where this has been moved, and the documentation still references the previous UI.

To test this, I've included a simple print(event) in my Lambda, and started modifying various components. So far I only print an empty dict ({}). I suspect it's in the launch.json but so far everything I've modified has not been picked up. Showing below

{
    "configurations": [
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "API token-to-geojson:HelloWorldFunction (python3.9)",
            "invokeTarget": {
                "target": "api",
                "templatePath": "token-to-geojson/template.yaml",
                "logicalId": "HelloWorldFunction"
            },
            "api": {
                "path": "/hello",
                "httpMethod": "get",
                "payload": {
                    "json": {}
                }
            },
            "lambda": {
                "runtime": "python3.9"
            }
        },
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "token-to-geojson:HelloWorldFunction (python3.9)",
            "invokeTarget": {
                "target": "template",
                "templatePath": "token-to-geojson/template.yaml",
                "logicalId": "HelloWorldFunction"
            },
            "lambda": {
                "payload": {
                    "ticky": "tacky"
                },
                "environmentVariables": {},
                "runtime": "python3.9"
            }
        }
    ]
}
1

There are 1 best solutions below

0
uudaddy On

The only thing I saw is we need to add "json" before the actual json data. In the example below, it appears the IDE already knows the id is event.id (note event is the first argument of the handler).

"lambda": {
                "payload": {
                    "json": {
                        "id": 1001
                    }
                },
                "environmentVariables": {}
            }