We’re migrating our webhook consumer from an EC2-based Kotlin service to AWS Lambda. The goal is to process routing.queue.conversation events from Genesys Cloud. The issue is the payload structure when using EventBridge as the transport.
When the webhook hits the Lambda, the event object contains the EventBridge metadata wrapper. I need to extract the actual Genesys Cloud payload from event.detail. Here’s the current handler logic:
exports.handler = async (event, context) => {
console.log("Received event:", JSON.stringify(event));
// Attempting to unwrap EventBridge payload
const gcPayload = event.detail || event;
if (!gcPayload || !gcPayload.id) {
console.error("Invalid payload structure", gcPayload);
return { statusCode: 400, body: "Bad Request" };
}
// Processing logic...
await processConversationEvent(gcPayload);
return { statusCode: 200, body: "OK" };
};
The problem is intermittent. Sometimes event.detail exists, but other times the payload seems to be at the root level, causing gcPayload.id to be undefined. I’ve checked the Genesys Cloud webhook configuration, and it’s set to use EventBridge. The X-Genesys-Signature header is present, but verifying it in the Lambda is tricky because the body hash calculation needs to match the raw payload Genesys sent, not the JSON-serialized EventBridge wrapper.
Is there a standard way to handle this dual-structure issue in Node.js? I’m seeing 400 errors in CloudWatch when the parser fails. The timestamp in the signature seems to drift if I’m hashing the wrong part of the event. Any examples of solid signature verification for EventBridge-wrapped Genesys payloads in Lambda?