IoT Analytics Lambda enhancementt

0

I'm trying to figure out how Lambda enhancement in the IoT analytics pipeline functions as it operates much differently then a normal lambda connected to IoT gateway. I can't seen to extract my incoming JSON data so I can manipulate in in Lambda as I do with normal lambdas outside IoT Analytics.

also if I want to output the event object from my incoming JSON payload in lambda from IoT gateway I can use a simple:

console.log(event); and then
var latitude = event.lat; //works properly

From cloudwatch I see my data output as:

INFO {
Reefer_ID: 34988,
size: 128,
color: 'green',
lat: 45.695406,
lon: -121.884298
}

But I cant extract the event object or its members from lambda from IoT gateway when using IoT analytics. I noticed the event object is slightly different which may be the issue. The IoT analytics event object from console.log in lambda is:

INFO [ { Reefer_id: 1235,
size: 128,
color: 'green',
lat: 45.695406,
lon: -121.884298 } ]

How do I assign the object members to a variable so that I can manipulate them?

thanks

Edited by: SteveB123 on Nov 24, 2019 12:53 PM

Edited by: SteveB123 on Nov 24, 2019 3:04 PM

Edited by: SteveB123 on Nov 24, 2019 3:05 PM

asked 4 years ago311 views
6 Answers
0
Accepted Answer

Yes in this pseudocode example, you would access latitude with message.lat inside the anonymous function.

AWS
Ryan_B
answered 4 years ago
0

Hi SteveB,

The integration between IoT Analytics pipeline and Lambda supports batching of messages. The default batch size is 1 when using the IoT Analytics console. This is why you see a list of one message instead of the same message forwarded by IoT Core.

To work with batched messages sent by IoT Analytics, you need to iterate through the received event array. An example:

let messagesReturnedToIoTAnalytics = [];
event.forEach(message => {
  // do some stuff to `message`
  // ...code...
  // then add to returned list
  messagesReturnedToIoTAnalytics.push(message);
});
return messagesReturnedToIoTAnalytics;

Hope this helps,
Ryan

AWS
Ryan_B
answered 4 years ago
0

Hi Ryan,

It definitely does help. I was going to look at the Python example from the user guy and try to work backwards so this helps. I will work on this today and Ill leave this open in case I get stumped again in the next couple of days, but this definitely helps. thanks!

answered 4 years ago
0

Hi Ryan,

It definitely does help. I was going to look at the Python google maps example from the user guide and try to work backwards so this helps. I will work on this today and I'll leave this open in case I get stumped again in the next couple of days, but this definitely helps.

which art of your pseudo code relates to the incoming ''event.member', in my case (event.lat)

is it message.lat' ? since your not defining 'message' I'm assuming this is really the incoming event object?

thanks

Edited by: SteveB123 on Nov 25, 2019 9:02 AM

answered 4 years ago
0

RyanB you are a genius, you have solved my problem after i've spend more then 6 hours on i,t to no avail. I would have had to work back from the Python example to even get a clue thatwe had to parse batched messages to extract the event objects members.

Do you know where is this documented? I'm looking through the IoT Analytics documentation and I don't see this issue listed anywhere. I'm wondering what AWS documentation explains this issue on another AWS service? Thanks again

Steve

answered 4 years ago
0

I will pass this feedback on to the service team. This behavior is documented in the IoT Analytics user guide, under the Lambda pipeline activity: https://docs.aws.amazon.com/iotanalytics/latest/userguide/pipeline-activities.html#aws-iot-analytics-pipeline-activities-lambda

The code for e in event: shows in Python that an iterator is needed to act on individual messages. We'll see about making it more clear that this is required even for a batch of one message.

Ryan

AWS
Ryan_B
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions