I’m wrestling with the structure of the v2.analytics.conversation.aggregate event coming through EventBridge to our Lambda. It’s not just a flat object, and the nesting is deeper than I expected for a simple aggregate.
Here’s a snippet of the payload I’m seeing in the CloudWatch logs:
{
"detail": {
"data": [
{
"id": "abc-123",
"metrics": {
"queue": {
"id": "456",
"value": 120
}
}
}
]
}
}
My Python handler is failing when I try to access event['detail']['data'][0]['metrics']['queue']['value']. Sometimes the metrics key is missing entirely if no queue metrics were recorded for that interval, which throws a KeyError.
I’ve tried:
- Using
event.get('detail', {}).get('data', [])to handle missing top-level keys. - Checking if
metricsexists before drilling down. - Looking at the CX as Code provider docs, but they don’t really cover runtime event parsing.
Is there a standard way to safely parse these aggregate events? The documentation for the analytics API is great for GET requests, but the webhook payload structure feels a bit opaque. I don’t want my Lambda crashing on every empty metric bucket.