Lambda webhook handler throwing 'Cannot read property of undefined' on GC payload

Looking for advice on parsing Genesys Cloud webhook events in a Node.js Lambda. The doc says the payload structure is standard, but event.body comes back as a string, not an object. I’m trying JSON.parse(event.body) but getting a syntax error on the first call.

Here’s the snippet:

exports.handler = async (event) => {
 const data = JSON.parse(event.body);
 console.log(data.conversations);
};

Why is the JSON invalid?

Make sure you wrap that parse in a try-catch block, aws often sends empty strings or malformed payloads that crash the lambda instantly. here’s how i structure it with otel tracing so i can see exactly where it fails:

const tracer = require('@opentelemetry/api').tracer('gc-webhook');
exports.handler = async (event) => {
 const span = tracer.startSpan('parse-gc-event');
 try {
 if (!event.body) throw new Error('Empty body');
 const data = JSON.parse(event.body);
 span.setAttribute('event.type', data.type);
 console.log(data.conversations);
 } catch (err) {
 span.recordException(err);
 console.error('Parse failed:', err.message);
 } finally {
 span.end();
 }
};