Invoke Lambda Payload

Problem

Preparing Payload for AWS Lambda Invoke Connector - the round trip of the request-response consists of first having to stringify JSON payload, and then parse the returned payload into a usable JSON.

Solution

This cookbook does not provide some magical sauce that will fix that problem, but you can use it by importing it into your flow and edit the nodes rather than setting everything up from scratch.

Example

invoke-lambda-payload.png

[{"id":"d4dc7b49.0f4928","type":"function","z":"a635abea.f55998","name":"parse payload","func":"msg.payload.baasResponse = JSON.parse(msg.baas.YOUR_LAMBDA_API_CONNECTOR_ALIAS.response.Payload)\nreturn msg;","outputs":1,"noerr":0,"x":920,"y":340,"wires":[["bdda85da.fe4d48"]]},{"id":"41560e3b.1af27","type":"change","z":"a635abea.f55998","name":"set baasPayload","rules":[{"t":"set","p":"payload.baasPayload.param_1","pt":"msg","to":"uno","tot":"str"},{"t":"set","p":"payload.baasPayload.param_2","pt":"msg","to":"dos","tot":"str"},{"t":"set","p":"payload.baasPayload.param_3","pt":"msg","to":"tres","tot":"str"},{"t":"set","p":"payload.baasPayload","pt":"msg","to":"$string(payload.baasPayload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":360,"wires":[["6952886b.bcd7c8"]]},{"id":"6952886b.bcd7c8","type":"baas","z":"a635abea.f55998","name":"YOUR_LAMBDA_API_CONNECTOR_ALIAS","alias":"YOUR_LAMBDA_API_CONNECTOR_ALIAS","contexts":[{"target":"Payload","source":"payload.baasPayload","sourceType":"msg"}],"x":630,"y":360,"wires":[["d4dc7b49.0f4928"],[]]},{"id":"bdda85da.fe4d48","type":"dialogue","z":"a635abea.f55998","name":"print response","message":"payload.baasResponse","messageType":"msg","displayTimer":1.5,"enableDisplay":false,"x":1120,"y":340,"wires":[[]]}]

To try it out simply copy the above json and import it in the flow designer.
Key shortcut Ctrl/⌘-i, Menu option Import

Discussion

Data setup

Use set baasPayload node to prepare data you want to include in the Payload, the very bottom Set is stringifying the payload using JSONata expression. change-node.png

BAAS

Rename the node and select your Lambda Connector from the dropdown.

Get Response

Inside the parse payload node change YOUR_LAMBDA_API_CONNECTOR_ALIAS to your Connector’s Alias.