Reputation: 57
I am working on a Lambda function that reads data from a file stored on S3 and writes it to an Aurora DB instance.
I can read the file in without a problem but when I try to access the key:value pairs it always comes back undefined.
I can run the code snippet in VSCode and it works.
I have tried every variation JSON.parse, JSON.stringify and any other manipulation I can think of.
Here is a portion of code that inspects the data at various states.
async function rdsWrite(objectRead) {
console.log("rdsWrite object ", objectRead, "typeof ", typeof(objectRead));
let person = new Object(objectRead);
console.log("person object ", person, "typeof ", typeof(person));
let personObj = JSON.parse(person);
console.log("personObj object ", personObj, "typeof ", typeof(personObj));
if(personObj.hasOwnProperty('middlename')){
console.log("has key");
} else {
console.log("does not have key");
}
The first console.log is the data coming directly from the S3 Read function and it returns the data and typeof string
The person console.log also returns the data and a typeof object
The personObj console.log returns the data as an object with a type of object.
I've used hasOwnProperty to see if anything returns the middlename key. I've used several keys.
In this image you can see the formatting of the AWS log. The first one is truncated at the beginning, the second is a single line and the third prints vertically.
I don't really know if the log formats are relevant.
The only thing I really need to know is why can't I get personObj.name or any other key:value pair?
Any help is appreciated. Thanks.
btw, the data is fake from Mockaroo so I'm not sharing any PII.
Upvotes: 0
Views: 374
Reputation: 57
Well, I guess it was waiting for me to post.
console.log(personObj[0].name)
now returns personObj name Albert Stubbeley
Upvotes: 1