Got a weird issue with a Lambda function handling Genesys Cloud webhooks. The function is set up to receive conversation events via an API Gateway endpoint, but it’s dropping payloads intermittently, especially after cold starts. The Genesys Cloud platform is sending the requests, and the API Gateway is logging the hits, but the Lambda handler isn’t processing them correctly.
Here’s the handler code:
exports.handler = async (event) => {
try {
const payload = JSON.parse(event.body);
console.log('Received payload:', payload);
// Process payload
return {
statusCode: 200,
body: JSON.stringify({ message: 'OK' })
};
} catch (error) {
console.error('Error processing webhook:', error);
return {
statusCode: 500,
body: JSON.stringify({ error: 'Internal Server Error' })
};
}
};
The problem is that sometimes event.body is undefined or malformed, causing the JSON.parse to fail. This results in a 500 error, which Genesys Cloud interprets as a failed delivery, triggering retries. The retries pile up, and eventually, the queue gets backed up.
I’ve checked the API Gateway settings, and everything looks correct. The Lambda function has the necessary permissions, and the memory settings are adequate. The issue seems to be related to how the payload is being passed from API Gateway to the Lambda function.
Has anyone run into this before? Any ideas on how to debug this further? Need to figure out why the payload is getting mangled or dropped.