We are seeing duplicate events hitting our Lambda function from the CXone EventBridge integration. Specifically, when an agent accepts a call, we get two identical com.nice.cxone.session.accepted events within a 200ms window.
I have the Lambda configured with FunctionResponseTypes: [ReportBatchItemFailures]. The code looks like this:
def lambda_handler(event, context):
batch_size = 10
responses = []
for record in event['Records']:
try:
# Process event
process_event(record['body'])
responses.append({
'itemIdentifier': record['messageId'],
'itemStatus': 'ProcessingSuccessful'
})
except Exception as e:
responses.append({
'itemIdentifier': record['messageId'],
'itemStatus': 'ProcessingFailed',
'itemFailureCode': 'DuplicatesNotAllowed'
})
return responses
The messageId is unique for each delivery, so I can’t use that for deduplication. I tried adding a check in DynamoDB using the sessionId and eventType as a composite key with a TTL, but the race condition is too tight. By the time the second request hits, the first one might not be committed yet, or they arrive in the same batch.
Is there a standard pattern for this in the CXone ecosystem? Or am I missing a setting in the EventBridge rule configuration to prevent this? The documentation doesn’t mention idempotency guarantees for these webhooks.
Here is a sample of the duplicate payload structure:
{
"source": "com.nice.cxone",
"detail-type": "Session Event",
"detail": {
"sessionId": "abc-123-def",
"eventType": "accepted",
"timestamp": 1678886400000
}
}
I’ve tried adding a delay in the Lambda, but that just increases cost and latency. We need a clean way to drop the second event if the first one was already processed successfully.