Getting SyntaxError: Unexpected token u in JSON at position 0 when running Lambda Test
This is because when you test your lambda with a packet, say
{
"var1": "2017-04-17T18:48:03.608Z",
"var2": "0.45",
"var3": "0.5"
}
Then that packet is passed as the event
to the handler.
However, you are doing JSON.parse(event.body)
, but for the above packet, event.body
is undefined
(which has token u
at position 0).
You should change your test packet to:
{
"body": "{\"var1\":\"2017-04-17T18:48:03.608Z\",\"var2\":\"0.45\",\"var3\":\"0.5\"}"
}
Note that the body is a stringified JSON, because API Gateway Lambdas expect event body in a stringified format.