AWS Lambda : JSON object undefined

0 votes

So, I have a lambda function which is called with, by an MQTT message in JSON. I am only attempting to log the values, and the top level dot fields work fine, but nested objects in the JSON are seen as "undefined". I also tried to JSON. stringify but in vain. Does anyone know how to fix this?

'use strict';
console.log('Loading function');
exports.handler = (event, context, callback) => {
  console.log('Received event:', JSON.stringify(event, null, 2)); // Complete message
  console.log('Received event.ApiVersion:',event.ApiVersion);
  console.log('Received event.CollectionID:',event.CollectionId);
  console.log('Received event.TagData.Time:',event.TagData.Time); //undefined

  var TimeObj = {}; 
  TimeObj = event.TagData.Time;
  console.log('Received event TimeObj:',TimeObj); //undefined
};

Here are the cloud watch logs/results:

Loading function
Received event:
{
 "FormatId": "TagValues",
 "ApiVersion": 1,
 "CollectionId": 2,
 "TagData": [
     {
         "Time": "2017-09-02T11:06:35.917000+02:00",
         "Values": {
             "var1": 16777216,
             "var2": 7534
         }
     }
 ]
}
Received event.ApiVersion: 1
Received event.CollectionID: 2
Received event.TagData.Time: undefined
Received event TimeObj: undefined

Jan 24 in IoT (Internet of Things) by Upasana
• 8,110 points
41 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Change

event.TagData.Time;

To

event.TagData[0].Time;


This should work.

answered Jan 24 by Shubham
• 12,710 points

Related Questions In IoT (Internet of Things)

0 votes
0 answers
0 votes
1 answer

How to work a AWS IOT Lambda with a devices?

Hey KanaguRaj, use this for reference: https://serverless.com/b ...READ MORE

answered Apr 12 in IoT (Internet of Things) by Vardhan
• 10,980 points
34 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Best Practices on AWS IoT

I would recommend you use Case 2 ...READ MORE

answered Dec 26, 2018 in IoT (Internet of Things) by Shubham
• 12,710 points
128 views
0 votes
1 answer

Arguments in boto3 AWS client

As long as you're explicitly providing credential ...READ MORE

answered Feb 11 in IoT (Internet of Things) by Shubham
• 12,710 points
211 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.