1

So I have this backend NodeJS Lambda, I send data to it from Angular.

From the NodeJS Lambda I run this code:

 const claims = event.requestContext.authorizer.claims;
        username = claims['cognito:username'];
        console.log(username);
        console.log(event.body);
        console.log(event.body['Description'])
        console.log(event.body.Description)

I can read the username from the authenticated user, and the event.body prints this (from Cloudwatch logs) :

2022-03-07T19:23:11.844Z    a456711f-3fc1-4aee-9864-246f51c7fe93    INFO    
{
    "Description": "Afspraak met dr maken",
    "Day": "April 5th at 2:30pm",
    "Priority": "High",
    "ID": 2,
    "Reminder": true
}

Both these statements print undefined though:

 console.log(event.body['Description'])
 console.log(event.body.Description)

I'm pretty sure i'm doing or forgetting something really stupid but can't seem to figure it out. Anybody willing to help?

davyioner
  • 111
  • 1
  • 9

1 Answers1

0

Found the mistake! Figured out by doing: console.log(typeof event.body); That event.body was just a string.

Used body = JSON.parse(event['body']) to parse it into a json object and now i can call body.Description.

Solved!

davyioner
  • 111
  • 1
  • 9