Daniel-t / node-red-contrib-aws

A collection of Node-RED nodes for AWS.
Apache License 2.0
56 stars 59 forks source link

How do I send msg.payload as the MessageBody to SQS? #47

Closed QAnders closed 5 years ago

QAnders commented 6 years ago

I am fairly novice with Node-Red and can't figure out how to send the {msg.payload} object from a previous node as message data to SQS... I've successfully sent messages to SQS but the message body is {msg.payload}, {{msg.payload}} or similar as that is what I've set for the message body in the node.

The same goes for DynamoDB... I've successfully created Items if I add the JSON in the node but I'd like to push it in on the Input.

Am I missing something or is it only using the text added in the Nodes as "body" to send to AWS?

Daniel-t commented 6 years ago

Can you provide an example (export to clipboard), that way I can see exactly what you're trying to do.

TibGva commented 6 years ago

I guess I understand that QAnders is trying to use msg.payload to feed the nodes like dynamoDB, but he should be using msg.Item per example for Dynamodb. Example:

msg.Item={ "myattribute1": {"S": msg.payload.bla}, "myattribute2": {"S": "abc"}, "myattribute3" : {"S" : "def"} };

QAnders commented 6 years ago

Problem seems to be that it is not possible to send a variable (=object value) as the message to SQS. It is sending the object/variable name as a string regardless of me trying to format it as JSON, msg.Item={} is the same, it is sent as a string, not as the object.

Daniel-t commented 6 years ago

It will be easier to help if you can provide an example (exported)

scsaba commented 6 years ago

I also have the same issue. I'd like to feed a DynamoDB node's PutItem operation with a dynamic input coming from another node. I did not manage to figure out what to put into the Item field. Whatever I enter it tries to parse as a string. E.g. if I put msg.payload, I would expect it to use the value of the msg.payload, but it tries to parse the "msg.payload" string itself, so I get an error: "SyntaxError: Unexpected token m in JSON at position 0"

I think @QAnders has the same problem.

image

scsaba commented 6 years ago

Based on the Rekognition sample I managed to sort out this issue by adding a func before the DynamoDB node that sets the msg.Item to msg.payload. The Item field needs to be empty in the DynamoDB node.

It's working like a charm now :)