Comments (5)
No, this is not normal... I'm seeing the same thing when using the aws lambda
node inside a split/join flow. In order for the join to work, the msg.parts
object must remain intact. Instead, the last one that was received is being returned by all the callbacks.
In my tests, I have an array of 3 msg objects, representing 3 sets of args to pass to Lambda. After the split
node, the first msg.parts
looks like this:
{"id":"52f290c1.afbc","type":"array","count":3,"len":1,"index":0}
but when returned from aws, the output msg.parts
index is set to the last input msg index value:
{"id":"52f290c1.afbc","type":"array","count":3,"len":1,"index":2}`
So after the join
, all of the results that were calculated in Lambda are placed into a 3-element array -- but since they all have index = 2, the output array is full of nulls, except for the last element:
[null, null, {... results of the last aws call ...}]
from node-red-contrib-aws.
Sorry I'm not following.
Can one of you provide a test scenario? With an example lambda script or dynamo table, and flow.
from node-red-contrib-aws.
Here is a thread on slack that highlights what I found:
https://node-red.slack.com/archives/C03M2TAQ8/p1544543818421100
Basically, the problem is within this code: (## comments are mine)
this.on('input', function(msg) { ## called with every new msg object
node.cb = function(err, data) { ## these args do not have a reference to the incoming object...
if (err) {
node.status({fill:"red",shape:"ring",text:"error"});
node.error("failed: " + err.toString(),msg);
return;
} else {
msg.payload = data; ## the scope of this msg object is outside of this callback function
node.status({});
}
node.send(msg); ## when the cb finally gets called, it uses the last msg that arrived
};
// pass 'msg' to lambda, and invoke callback...
## when multiple msgs arrive, they all get passed to AWS before any node.cb function is invoked
ec2.invoke(params, node.cb);
});
This is not a problem only with AWS, but with any async call that invokes a callback function when it returns its data. I'll see if I can find an example of how this is handled in other async service nodes.
from node-red-contrib-aws.
Ok, it looks like one technique is to pass the incoming msg
object to a function that returns another function, which has the signature expected by the AWS callback logic -- something like this (untested):
this.on('input', function(msg) {
function aws_cb(msg_in) {
return function(err, data) {
if (err) {
node.status({fill:"red",shape:"ring",text:"error"});
node.error("failed: " + err.toString(), msg_in);
return;
} else {
msg_in.payload = data;
node.status({});
}
node.send(msg_in);
};
};
// pass incoming 'msg' to lambda, and invoke callback with original msg...
ec2.invoke(params, aws_cb(msg));
});
So each time a new msg arrives, we create a callback function by passing in the msg object:
aws_cb(msg)
That callback function contains the original msg object (and its "parts" property for the join node to work correctly).
from node-red-contrib-aws.
I expect this to be resolved in the recent update. (which changed the scope of the msg object)
from node-red-contrib-aws.
Related Issues (20)
- /usr/src/node-red/node_modules/node-red-contrib-aws/Ecs.html does not exist HOT 2
- How to add '--detection-attributes "ALL"' to Rekognition/ Indexfaces node HOT 1
- Dependency Issue with agent-base <6.0.0 and Node-RED 2.0 HOT 2
- Autogeneration for all AWS API HOT 4
- Feature request: Allow credentials to be supplied by ECS container HOT 3
- How to pass image to AWS Rekognition node? HOT 1
- [error] [AWS Rekognition:text] SyntaxError: Unexpected token i in JSON at position 0 HOT 1
- How I can view aws rekognition output image?
- EC2 StartInstance "SyntaxError: Unexpected token i in JSON at position 0" HOT 5
- add cloud watch api in node-red-contrib-aws
- Example flow for EC2 services
- Error outputs do not include original msg data HOT 1
- DynamoDB usage examples Please HOT 1
- PutRecord Kinesis passing data does not handle the payload HOT 2
- Security Token Service Node not available after build HOT 1
- SQS: How to set request parameters for ReadMessage? HOT 2
- Rekognition not returning label instances HOT 3
- Enhancement : S3 : Allow for endpoint url to be passed (for s3 interface endpoints)
- Billing?
- Feature Request: IAM auth with SessionToken HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-red-contrib-aws.