I’m trying to filter conversation.end events from EventBridge to a specific queue. The current setup processes every end event, which is noisy. I need to check the queue.id in the payload before processing. Here’s the handler:
exports.handler = async (event) => {
const queueId = event.detail.queue.id;
if (queueId !== 'target-queue-id') return;
// process
};
Is there a better way to filter this at the source or in the EventBridge rule itself to avoid cold starts?
That event.detail.queue.id check works, but you’re still paying for every invocation. It’s better to push the filtering logic into the EventBridge rule itself so the Lambda never wakes up for irrelevant traffic. You can use an event pattern with a numeric or string filter on the detail.queue.id field directly in the AWS console or via the aws-sdk in your deployment script.
Here’s what the event pattern JSON looks like. You attach this to your rule instead of a wildcard source. This cuts down the noise before it even hits your code.
{
"source": ["genesys.cloud"],
"detail-type": ["conversation.end"],
"detail": {
"queue": {
"id": ["target-queue-id"]
}
}
}
Just make sure the queue ID matches exactly. If you’re pulling the ID dynamically, you’ll need to update the rule or use a different approach, but for static targets this is the way to go.